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 cannot be returned by writable reference because it is a readonly variable
Example
The following sample generates CS8334:
// CS8334.cs (5,14)
class Program
{
static ref int M(in int arg1, in (int Alice, int Bob) arg2)
{
return ref arg2.Alice;
}
}
To correct this error
To return a reference to a read-only member, refactoring to return ref readonly will correct this error:
class Program
{
static ref readonly int M(in int arg1, in (int Alice, int Bob) arg2)
{
return ref arg2.Alice;
}
}
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.