Hi, this can not be done. new A() is an object, it could have a name. objectA is not an object, it is a variable, it holds a reference to the class A object. There could be many more references to the same object, it suffices to do A* objectB=objectA;, now how would the class A object have to know the name of all the variables pointing to it, and in particular the one you want?? Suggestion: give your objects a name by providing a Name property and/or a name argument in their constructor, so new A("aha"); would create a new class A object and give it the name "aha". Now you can ask that object for its name, and/or you can override its ToString() method so it identifies itself. Remark: this works independently of the variable(s) that may refer to that object! :)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets