Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Error CS0631

ref and out are not valid in this context

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

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()
    {
    }
}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.