I
Ian Lazarus
Hello,
My question is whether it is possible to avoid assignment on the left hand
side of an overloaded operator << expression, as in the code below. Without
the assignment, the compiler complains.
class myclass
{
public static myclass operator << (myclass lhs, int rhs)
{
return(lhs);
}
public static void Main()
{
myclass x = new myclass();
int a = 1;
int b = 2;
int c = 3;
x << a << b << c;
// error CS0201: Only assignment, call, increment, decrement, and
new // object expressions can be used as a statement
}
}
So instead, I have to write:
x = x << a << b << c;
Is there a way to avoid the assignment?
Thanks
My question is whether it is possible to avoid assignment on the left hand
side of an overloaded operator << expression, as in the code below. Without
the assignment, the compiler complains.
class myclass
{
public static myclass operator << (myclass lhs, int rhs)
{
return(lhs);
}
public static void Main()
{
myclass x = new myclass();
int a = 1;
int b = 2;
int c = 3;
x << a << b << c;
// error CS0201: Only assignment, call, increment, decrement, and
new // object expressions can be used as a statement
}
}
So instead, I have to write:
x = x << a << b << c;
Is there a way to avoid the assignment?
Thanks