C# Error
CS1655 – Cannot use fields of ‘{0}’ as a ref or out value because it is a ‘{1}’
Reason for the Error & Solution
Cannot pass fields of ‘variable’ as a ref or out argument because it is a ‘readonly variable type’
This error occurs if you are attempting to pass a member of a variable, a variable, or a variable to a function as a ref or out argument. Because these variables are considered read-only in these contexts, this is not allowed.
The following sample generates CS1655:
// CS1655.cs
struct S
{
public int i;
}
class CMain
{
static void f(ref int iref)
{
}
public static void Main()
{
S[] sa = new S[10];
foreach(S s in sa)
{
CMain.f(ref s.i); // CS1655
}
}
}