operator ++

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
 
F

Fabien Bezagu

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
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top