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.
An expression cannot be used in this context because it may not be passed or returned by reference
Example
The following sample generates CS8156:
// CS8156.cs (7,27)
class Test
{
delegate ref int D1();
void Test1()
{
D1 d1 = () => ref 2 + 2;
}
}
To correct this error
When not using referenceable variables, refactoring to return by value corrects this error:
class Test
{
delegate int D1();
void Test1()
{
D1 d1 = () => 2 + 2;
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.