Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to know when was an object created?

Tags:

c#

I have no practical need for this, but I was wondering:

is there anyway in C# to know, for any two arbitrary objects, which one was created first?

like image 644
Galactus Avatar asked Mar 15 '13 19:03

Galactus


2 Answers

No. Unless the object has a read-only property that stored the date and time that the object was created, there's no way to know.

like image 133
Justin Niessner Avatar answered Sep 24 '22 19:09

Justin Niessner


Only if, inside the constructor of the object, you store the current date/time (note that DateTime.Now almost certainly has insufficient precision to be useful) and provide some means of exposing that information publicly.

like image 31
Servy Avatar answered Sep 24 '22 19:09

Servy