someone in my team stumbled upon a peculiar use of the ref keyword on a reference type
class A { /* ... */ }
class B
{
public void DoSomething(ref A myObject)
{
// ...
}
}
Is there any reason someone sane would do such a thing? I can't find a use for this in C#
Only if they want to change the reference to the object passed in as myObject
to a different one.
public void DoSomething(ref A myObject)
{
myObject = new A(); // The object in the calling function is now the new one
}
Chances are this is not what they want to do and ref
is not needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With