Friday, September 5, 2008

C# program to Demonstrate the difference between prefix

using System;

class PrePostDemo {
public static void Main() {
int x, y;
int i;

x = 1;
Console.WriteLine("Series generated using y = x + x++;");
for(i = 0; i < 10; i++) {

y = x + x++; // postfix ++

Console.WriteLine(y + " ");
}
Console.WriteLine();
x = 1;
Console.WriteLine("Series generated using y = x + ++x;");
for(i = 0; i < 10; i++) {

y = x + ++x; // prefix ++

Console.WriteLine(y + " ");
}
Console.WriteLine();

}
}

0 comments: