Ref:
Ref is used to pass parameters by reference
Any changes made to the parameter in the method will be reflected in the variable
ref parameter must be initialized before its use
Out:
Out is used to pass parameters by reference
Parameter not required to be initialized before use
Any changes made to the parameter in the method will be reflected in the variable
CodeListing:Ref
class RefExample
{
static void Method(ref int i)
{
i=44;
}
static voic Main()
{
int val=0;
Method(ref val) // val is now 44
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment