How to implement overloading for postfix and prefix operators in C #
void Main()
{
MyClass myclass=new MyClass();
myclass.x=5;
Console.WriteLine((++myclass).x);
Console.WriteLine((myclass++).x);
}
public class MyClass
{
public int x;
public static MyClass operator ++(MyClass m)
{
m.x=m.x+1;
return m;
}
}
this may be an unnecessary operator overload, but it is known that the ++ operator can be overloaded. How can we achieve different behavior here (i ++, ++ i)
source
share