C# Error CS0631 – ref and out are not valid in this context

C# Error

CS0631 – ref and out are not valid in this context

Reason for the Error & Solution

ref and out are not valid in this context

The declaration for an cannot include the use of or parameters.

Example

The following sample generates CS0631:

// CS0631.cs  
public class MyClass  
{  
    public int this[ref int i]   // CS0631  
    // try the following line instead  
    // public int this[int i]  
    {  
        get  
        {  
            return 0;  
        }  
    }  
}  
  
public class MyClass2  
{  
    public static void Main()  
    {  
    }  
}  

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...