What I mean by the subject is, is it possible to print out a string that is aware of the name of the variable it is stored in?

For example... I'm reading right now about overriding a class's ToString() method, and I want to know if there exists a way to call myObject.ToString(); and have it print out the name of the variable that the object is stored in, and the object data? Like, an example output would be myObject = [var1: 1; var2: 2; var3: 3]

9 Years
Discussion Span
Last Post by Ramesh S

Adding to that.
1) The reference types can have more than one reference to the themselves. It would be ambiguous getting variable names even if you were able to access such information.
2) The debugger can know names of variables and other information from the metadata. But only when compiled for debugging and you cannot access them programmatically.
3) You can do this though.

Votes + Comments
Very nice link.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.