'out' vs. 'ref'

is there some sample, where can to see the diference between both?

[74 byte] By [serghio] at [2008-3-3]
# 1
The difference is quite simple. "ref" is used for both input and output. For example...

void CleanString( String ref stringToClean)
{
StringBuilder sb = new StringBuilder( stringToClean);

// Replace underscores with spaces
sb.Replace( '_', ' ');

stringToClean = sb.ToString();
}

Notice that "stringToClean" is both read from and written to, so a ref is in order.
void GetSomeValue( String out someValue)
{
someValue = "some value";
}
Notice that someValue is only written to. You could use a ref in the second instance, but the user of GetSomeValue would have to initialize someValue before passing it in. Why make them do that if it's not needed?
Hope this helps!

dkocur2 at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# Language...