I am doing some code review and I stopped on the following construct. Is this the Correct way of using ReferenceEquals
to check if a method returned actually the same object that was passed as an argument or a new one?
int x = 5;
Foo f = new Foo()
Foo DoSomething(Foo f)
{
if(x > 5)
{
return f;
}
else
{
return new Foo();
}
}
Foo ff = DoSomething(f);
if(Object.ReferenceEquals(ff, f))
{
//do something
}