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

Join The Discussion