C# Error CS1510 – A ref or out value must be an assignable variable

C# Error

CS1510 – A ref or out value must be an assignable variable

Reason for the Error & Solution

A ref or out argument must be an assignable variable

Only a variable can be passed as a parameter in a method call. A ref value is like passing a pointer.

Example

The following sample generates CS1510:

// CS1510.cs  
public class C  
{  
   public static int j = 0;  
  
   public static void M(ref int j)  
   {  
      j++;  
   }  
  
   public static void Main ()  
   {  
      M (ref 2);   // CS1510, can't pass a number as a ref parameter  
      // try the following to resolve the error  
      // M (ref j);  
   }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...