What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 10 , b = 20;
Console.WriteLine("Result before swap is: "+ a +" "+b);
swap(ref a, ref b);
Console.ReadLine();
}
static void swap(ref int i, ref int j)
{
int t;
t = i;
i = j;
j = t;
Console.WriteLine("Result after swap is:"+ i +" "+j);
}
static void Main(string[] args)
{
int a = 10 , b = 20;
Console.WriteLine("Result before swap is: "+ a +" "+b);
swap(ref a, ref b);
Console.ReadLine();
}
static void swap(ref int i, ref int j)
{
int t;
t = i;
i = j;
j = t;
Console.WriteLine("Result after swap is:"+ i +" "+j);
}A. Result before swap is: 20 10
Result after swap is: 20 10
B. Result before swap is: 10 20
Result after swap is:20 10
C. Result before swap is: 10 20
Result after swap is:10 20
D. Result before swap is: 20 10
Result after swap is:10 20
Answer: Option B
Related Questions on Classes and Objects in C Sharp
A. A blueprint for creating objects
B. A method in C#
C. A variable in C#
D. A data type in C#
A. A method in C#
B. A variable in C#
C. An instance of a class
D. A data type in C#
A. public
B. private
C. protected
D. internal

Join The Discussion