Consider the following example, here int i is passed for the reference.
My question is, Can i pass a reference type to out? like object (i.e) static void sum(out OutExample oe)
class OutExample
{
static void Sum(out int i)
{
i = 5;
}
static void Main(String[] args)
{
int val;
Sum(out val);
Console.WriteLine(val);
Console.Read();
}
}
Now the below code having some error,
class OutExample
{
int a;
static void Sum(out OutExample oe)
{
oe.a = 5;
}
static void Main(String[] args)
{
int b;
OutExample oe1=new OutExample();
Sum(out oe);
oe.b=null;
Console.WriteLine(oe.b);
Console.Read();
}
}
Finally Got the Answer!
class OutExample
{
int a;
int b;
static void Sum(out OutExample oe)
{
oe = new OutExample();
oe.a = 5;
}
static void Main(String[] args)
{
OutExample oe = null;
Sum(out oe);
oe.b = 10;
Console.WriteLine(oe.a);
Console.WriteLine(oe.b);
Console.Read();
}
}