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#.
|