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]

Recommended Answers

All 3 Replies

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.

commented: Very nice link. +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.