Ref in C#
C#
2
Posts
2
Posters
0
Views
1
Watching
-
When would be the best time in your own opinion to use the ref in C#? :) "To teach is to learn twice"
When you need to modify the source variable rather than a copy of it. Example:
void Test()
{
string str="UnModified";
RefTest(ref str);
//str now == "Modified!"
}void RefTest(ref string s)
{
s="Modified!";
}"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi