6

Possible Duplicate:
Difference between ref and out parameters in .NET

When to use ref and when to use out ? What is difference between the both ? How and where they are used ?

Please share an example showing difference between the both ref and out .

  • Thanks.
Community
  • 1
  • 1
Pratik
  • 11,534
  • 22
  • 69
  • 99

3 Answers3

5

To my understanding:

ref means passing a variable by reference, which means you pass a pointer to that variable and it will retain modifications after leaving the function.

out means basically the same, except that the variable must be assigned before the function is exited, pretty much like return statements must be met before the function reaches completion.

bevacqua
  • 47,502
  • 56
  • 171
  • 285
1

I would start here. Jon does a good job explaining it all:

http://www.yoda.arachsys.com/csharp/parameters.html

kemiller2002
  • 113,795
  • 27
  • 197
  • 251
-1

There's any number of examples online.

A quick Google search found this: http://www.c-sharpcorner.com/UploadFile/mahesh/out_and_ref11112005002102AM/out_and_ref.aspx

Nathan
  • 1,591
  • 4
  • 17
  • 22