CSharp examples for Language Basics:Operator
Prefix increment and postfix increment operators.
using System;/*ww w . j ava2 s .c o m*/ class Increment { static void Main() { // demonstrate postfix increment operator int c = 5; // assign 5 to c Console.WriteLine($"c before postincrement: {c}"); // displays 5 Console.WriteLine($" postincrementing c: {c++}"); // displays 5 Console.WriteLine($" c after postincrement: {c}"); // displays 6 Console.WriteLine(); // skip a line // demonstrate prefix increment operator c = 5; // assign 5 to c Console.WriteLine($" c before preincrement: {c}"); // displays 5 Console.WriteLine($" preincrementing c: {++c}"); // displays 6 Console.WriteLine($" c after preincrement: {c}"); // displays 6 } }