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.
Cannot return by reference a member because it was initialized to a value that cannot be returned by reference
The following sample generates CS8158:
// CS8158.cs (11,14)
public class Test
{
public struct S1
{
public char x;
}
ref char Test1(char arg1, S1 arg2)
{
ref S1 r = ref arg2;
return ref r.x;
}
}
To return members initialized to a value that cannot be returned by reference, refactoring to return by value corrects this error:
char Test1(char arg1, S1 arg2)
{
ref S1 r = ref arg2;
return r.x;
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: