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.
The expression must be of type because it is being assigned by reference
When assigning a reference to a variable, the type of the variables must match to be referenceable.
Example
The following sample generates CS8173:
// CS8173.cs (12,18)
class C
{
void M()
{
string s = "s";
object o = s;
ref string rs = ref s;
ref object ro = ref o;
ro = ref s;
}
}
To correct this error
Assigning the reference to a variable of the correct type will correct this error:
rs = ref s;
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.