'out' vs. 'ref'
is there some sample, where can to see the diference between both?
is there some sample, where can to see the diference between both?
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!