I\'ve read the difference between passng and not passing ref in parameters, however, when would I want to use them?
For example, I had some logic in a method which c
Conceptually, the difference is that a value type stores its value directly, whereas a reference type stores a reference to the value. Maybe you should re-read a bit about reference vs value types.
Passing value types by reference--as demonstrated above--is useful, but ref is also useful for passing reference types. This allows called methods to modify the object to which the reference refers because the reference itself is being passed by reference. The following sample shows that when a reference type is passed as a ref parameter, the object itself can be changed.
class RefRefExample
{
static void Method(ref string s)
{
s = "changed";
}
static void Main()
{
string str = "original";
Method(ref str);
// str is now "changed"
}
}
MSDN