Is it possible to get the variable name using which the object was called in C#? Or is it possible to get all the variable which are referring a particular object?
EDIT:
Just to clarify further even though this has been answered.
Consider the code sample given by Fredrik Mörk
User someUser = new User();
User anotherVariable = someUser;
i.Is it possible to find someUser using the object reffered by anotherVariable.
ii. Is it possible to find get the name of the variable using which the object was called. That is something like someUser.getName() should give “someUser” as output.
No, there’s no support for this. Of course, if you have a set of “candidate” variables (e.g. “find all the instance variables in this type, here’s a bunch of objects of that type”) then you can check whether any of them currently refer to a specific value. But otherwise, no.