postincrement and preincrement in c#

Today I was working in C# and I write a code like this.

I see the value it returns is 4, not 5. What could go wrong?. The reason is my function return the object before increment it (apply +1). So what thing is in it that is a little uneasy to understand

When you return n++, you return n and then modifying the object.  If you return ++n you are modifying the object and then returning the value.

Leave a Reply

Your email address will not be published. Required fields are marked *