/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example3_8.cs illustrates the use of
prefix and postfix versions of the
increment and decrement operators
*/
public class Example3_8
{
public static void Main()
{
// postfix increment
int length = 3;
int newLength = length++;
System.Console.WriteLine("Postfix increment example");
System.Console.WriteLine("length = " + length);
System.Console.WriteLine("newLength = " + newLength);
// prefix increment
length = 3;
newLength = ++length;
System.Console.WriteLine("Prefix increment example");
System.Console.WriteLine("length = " + length);
System.Console.WriteLine("newLength = " + newLength);
// postfix decrement
length = 3;
newLength = length--;
System.Console.WriteLine("Postfix decrement example");
System.Console.WriteLine("length = " + length);
System.Console.WriteLine("newLength = " + newLength);
// prefix decrement
length = 3;
newLength = --length;
System.Console.WriteLine("Prefix decrement example");
System.Console.WriteLine("length = " + length);
System.Console.WriteLine("newLength = " + newLength);
}
}
|