++ Operator (C#)

        static void Main(string[] args)
        {
            int i = 0;
            //The first form is a prefix increment operation.
            //The result of the operation is the value of the
            //operand after it has been incremented.
            int b = ++i;
            Console.WriteLine("{0}, {1}", b, i);
            //output: 1, 1
 
            i = 0;
            Console.WriteLine(IncrementThenReturn(i));
            //output: 1
 
            i = 0;
            Console.WriteLine(ReturnParameter(++i));
            //output: 1
 
            //The second form is a postfix increment operation.
            //The result of the operation is the value of the
            //operand before it has been incremented.
            i = 0;
            int a = i++;
            Console.WriteLine("{0}, {1}", a, i);
            //output: 0, 1
 
            i = 0;
            Console.WriteLine(ReturnThenIncrement(i));
            //output: 0
 
            i = 0;
            Console.WriteLine(ReturnParameter(i++));
            //output: 0
            Console.ReadKey();
        }
 
        static int IncrementThenReturn(int i)
        {
            return ++i;
        }
 
        static int ReturnThenIncrement(int i)
        {
            return i++;
        }
 
        static int ReturnParameter(int i)
        {
            return i;
        }
    }
 
See also msdn

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s