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.
Members of readonly field cannot be returned by writable reference
The following sample generates CS8162:
// CS8162.cs (12,14)
public class Test
{
public struct S1
{
public char x;
}
public readonly S1 i2;
ref char Test1()
{
return ref i2.x;
}
}
To return the value of a readonly
field, refactoring to return by value corrects this error:
public class Test
{
public struct S1
{
public char x;
}
public readonly S1 i2;
char Test1()
{
return i2.x;
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: