#5 Ref and Out Parameters

int NormalVaribale = 1;
 int referencevariable = 1;
 int outvaraibale = 1;

 referencemethod(ref referencevariable);
 outmethod(out outvaraibale);
 Console.WriteLine("Normal Variable"+NormalVaribale);
 Console.WriteLine("(REF)Reference Variable"+referencevariable);
 Console.WriteLine("(out) Out Varaible"+outvaraibale);

ref :Value must be Initialized before it is passed to the method. Reference is being passed to the method,so the value changed will get reflected./*It has got Nothing to do with value type and reference type both of these can use ref*/

out:Value need not be Assigned,but has to be defined before the method exists.

Note:Even though you have initialized before passing to method,you got to assign value before the method exists.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s