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 initialize a by-reference variable with a value
Example
The following sample generates CS8172:
// CS8172.cs (10,17)
class C
{
void M()
{
ref readonly int L() => ref (new int[1])[0];
ref readonly int x = ref L();
ref int y = x;
}
}
To correct this error
Assigning a reference to a variable to a by-reference variable corrects this error:
class C
{
void M()
{
ref readonly int L() => ref (new int[1])[0];
ref readonly int x = ref L();
ref int y = ref x;
}
}
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.