public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

ref and out in C#

Posted by Virendra Dugar on February 3, 2009

When we pass a parameter as ref to a method, the method refers to the same variable and changes made will affect the actual variable. Even the variable passed as out parameter is similar to ref, but there are few implementation differences when you use it in C# .

Argument passed as ref must be initialized before it is passed to the method, where as in case of out its is not necessary,but after a call to the method as an out parameter the variable must be initialized.

When to use ref and out parameter

Out parameter can be used when we want to return more than one value from a method.

Enjoy..

Advertisements

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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: