How do I obtain an ID that allows me to tell difference instances of a class apart?

前端 未结 6 1993
谎友^
谎友^ 2021-02-02 13:30

Imagine I have a single class, with two instances:

MyClass a = new MyClass();
MyClass b = new MyClass();

MyClass has a method PrintUniqueInstan

6条回答
  •  情书的邮戳
    2021-02-02 14:06

    You cannot inherit all your classes from a base class or interface and require implementation of a UniqueID property?

    Another possibility is to wrap them in a class containing a generic object reference and the unique ID, then cataloging them as they are asked for in a lazy way. Cleaning up such a catalog of unique assignments could be awkward.

提交回复
热议问题