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);  
   }  
}