operator ++

  • Thread starter Thread starter Mohan
  • Start date Start date
M

Mohan

Hi,

How to overload the ++ operator, Prefix ++ and postfix ++ in C#.

Do we need to use the Dummy parameter like in C++ or is there any other
way to distinguish.


Thanks
Mohan
 
Mohan,

The syntax is :

public static MyClass operator ++(MyClass x)
{
return new MyClass(x.Member++);
}

The same operator is called for postfix and prefix.

Fabien
 
How to overload the ++ operator, Prefix ++ and postfix ++ in C#.

You overlaod ++ just like the other overloadable operators, but you
can't provide different implementations for prefix and postfix.



Mattias
 
Back
Top