In the case of Out - no assignment is required, but you must assign a value in which function this is passed,
For Ex:
using System;
namespace ConsoleApplication2
{
///
/// Summary description for Class1.
///
class Class1 {
public static void Foo_Ref(ref int i)
{
//i = 2; //Dont gives a error
}
public static void Foo_Out(out int i)
{
//i=3; //it gives an error i must be assigned before leaving this function.
}
public static void Test()
{
int a ; Foo_Ref(ref a); //it gives an error coz a is not assigned a value
Console.WriteLine("Ref Case {0}",a);
Foo_Out(out a);
Console.WriteLine("Out Case {0}",a);
}
[STAThread] static void Main(string[] args)
{ //return MessageBoxA(0,"Hello Irfan","Caption",0);
Test();
Console.Read();
}
}
}
No comments:
Post a Comment