What will be the output of the following C# code?
{
struct abc
{
public int i;
}
class Program
{
static void Main(string[] args)
{
sample a = new sample();
a.i = 10;
fun(ref a);
Console.WriteLine(a.i);
}
public static voidn fun(ref sample x)
{
x.i = 20;
Console.WriteLine(x.i);
}
}
}
{
struct abc
{
public int i;
}
class Program
{
static void Main(string[] args)
{
sample a = new sample();
a.i = 10;
fun(ref a);
Console.WriteLine(a.i);
}
public static voidn fun(ref sample x)
{
x.i = 20;
Console.WriteLine(x.i);
}
}
}A. 10
10
B. 20
10
C. 10
20
D. 20
20
Answer: Option D
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