View Single Post
  #1 (permalink)  
Old June 5th, 2006, 01:05 PM
furqanms furqanms is offline
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem to Swap two number in C#

I have try the following code in Turbo C it works fine.
but when i try the same in C# it not give me a proper result.i dont know why it so

Turbo C
================================================== ===================
#include<stdio.h>
void main()
{
       int a,b;
       a=10;
       b=20;
       //Before swap two numbers
       printf("a = %d\n",a);
       printf("b = %d\n",b);

       //After swap two numbers
       a^=b^=a^=b;
       printf("a = %d\n",a);
       printf("b = %d\n",b);
}
Output
a = 10
b = 20
a = 20
b = 10

C#
================================================== ===================
using System;
class myclass
{
        public static void Main()
        {
                int a,b;
                a=10;
                b=20;
                //Before swap two numbers
                Console.WriteLine("a = {0}",a);
                Console.WriteLine("b = {0}",b);

                //After swap two numbers
                a^=b^=a^=b;
                Console.WriteLine("a = {0}",a);
                Console.WriteLine("b = {0}",b);
        }

}
Output
a = 10
b = 20
a = 0
b = 10

if any one know then help me to understand why the output is differ in c and c#.