In C# given a function with the below signature
public static void Foo(ref int x, ref int y)
If the function was called using
int A = 10;
Foo(ref A, ref A)
Inside the function Foo is it possible to test that the x and y arguments reference the same variable? A simple equivalent test of x and y isn’t sufficient as this is also true in the case two different variable have the same value.
If you’re willing to use unsafe code, you can compare the underlying variable addresses:
(Edited to remove
unsafefrom method signature, based on @Michael Graczyk’s comment.)