Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a built in way to identify instances of a class?

I am doing some diagnostic logging with one of my C#.NET projects and I would like to be able to log an identifier that represents a specific instance of a class. I know I could do this with a static variable that just gets incremented every time a class instance is created but I am just wondering if there is any built-in way in the .NET framework to do this. Maybe using reflection or something.

like image 759
PICyourBrain Avatar asked Aug 25 '10 20:08

PICyourBrain


People also ask

How do I get an instance of a class in Python?

There are two ways to access the instance variable of class:Within the class by using self and object reference. Using getattr() method.

What are the instances of a class?

An instance of a class is an object. It is also known as a class object or class instance. As such, instantiation may be referred to as construction. Whenever values vary from one object to another, they are called instance variables.

How do I find the instance of a class in Java?

The instanceof operator in Java is used to check whether an object is an instance of a particular class or not. objectName instanceOf className; Here, if objectName is an instance of className , the operator returns true . Otherwise, it returns false .


1 Answers

You could add a Guid property to your class an initialize it in the constructor (guaranteed unique for each instance).

like image 53
Jon B Avatar answered Sep 23 '22 16:09

Jon B