Why must use "out" instead of ref ?
- by Phsika
i wrote some code blocks about ref -out declaration. i think that ref is most useful out. Ok. why i need to use out. i can use always ref everytime:
namespace out_ref
{
class Program
{
static void Main(string[] args)
{
sinifA sinif = new sinifA();
int test = 100;
sinif.MethodA(out test);
Console.WriteLine(test.ToString());
sinif.MethodB(ref test);
Console.WriteLine(test.ToString());
Console.ReadKey();
}
}
class sinifA
{
public void MethodA(out int a)
{
a = 200;
}
int _b;
public void MethodB(ref int b)
{
_b = b;
b = 2*b;
}
}
}