Archive for October, 2006

out and ref in c#

Wednesday, October 25th, 2006

out.cs

class zzz
{
public static void Main()
{
yyy a;
int i;
a=new yyy();
a.abc(out i);
System.Console.WriteLine(i);
}
}
class yyy {
public void abc( out int i) {
i=10;
}
}
//bcoz of out 10 else 100
//out makes available the changes outside class

ref.cs

class zzz
{
public static void Main()
{
yyy a;
int i=100;//have to initialize in ref
a=new yyy();
a.abc(ref i);
System.Console.WriteLine(i);
}
}
class yyy
{
public void abc( ref int i)
{
i=10;
}
}