Ref vs out in C #

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

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

Please tell us an example showing the difference between ref and out .

  • Thanks.
+4
source share
3 answers

There are several examples online.

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

0
source

As far as I understand:

ref means passing the variable by reference, which means that you are passing a pointer to this variable, and it will save the changes after exiting the function.

out means basically the same thing, except that the variable must be assigned before the function is completed, almost the same as the return statements must be executed before the function completes.

+4
source

I would start here. John explains this pretty well:

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

+1
source

All Articles