In c# , when sending a parameter to a method, when should we use "ref" and when "out" and when without any of them?
['https://Stackoverflow.com/questions/1115762', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/61156/']
(this is supplemental to the existing answers - a few extra considerations)

There is another scenario for using `ref` with C#, more commonly seen in things like XNA... Normally, when you pass a value-type (`struct`) around, it gets cloned. This uses stack-space and a few CPU cycles, and has the side-effect that any modifications to the `struct` in the invoked method are lost.

(aside: normally `struct`s should be immutable, but mutable structs isn't uncommon in XNA)

To get around this, it is quite common to see `ref` in such programs.

But in **most** programs (i.e. where you are using `class`es as the default), you can *normally* just pass the reference "by value" (i.e. no `ref`/`out`).

---

Another **very** common use-case of `out` is the `Try*` pattern, for example:

```
string s = Console.ReadLine();
int i;
if(int.TryParse(s, out i)) {
    Console.WriteLine("You entered a valid int: " + i);
}

```

Or similarly, [`TryGetValue`](http://msdn.microsoft.com/en-us/library/zkw5c9ak(VS.85).aspx) on a dictionary.

This could use a tuple instead, but it is such a common pattern that it is reasonably understood, even by people who struggle with too much `ref`/`out`.
ref is to be avoided (I beleive there is an fx-cop rule for this also) however use ref when the object that is reference may itself changed. If you see the 'ref' keyword you know that the underlying object may no longer be referenced by the same variable after the method is called.