Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A readonly field cannot be returned by writable reference
The following sample generates CS8160:
// CS8160.cs (8,20)
class Program
{
readonly int i = 0;
ref int M()
{
return ref i;
}
}
To return a readonly
field, refactor to return by value:
class Program
{
readonly int i = 0;
int M()
{
return i;
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: