2

Possible Duplicate:
.NET unique object identifier

Instead of re-inventing the wheel, is there a unique, immutable object ID I can access for each object instance in .NET?

I'm asking this because I find myself writing the same code many times: Add a field or a property named Id, with type of Guid. This is useful mainly for logging purpose.
Example:

Logger.Debug(string.Format("about to save data to file, my id is {0}", this.Id)); 

Is there something built in the .NET framework instead of coding and using this.Id?
Surely there's nothing immediate, but maybe something using .NET internals.

Update:

I intentionally don't want to use the GetHashCode technique, or any related hash code mechanism.

2

1 Answer 1

1

No. There is no such field.

Some "alternatives" may be using the object's [default] hash code or using ObjectIDGenerator, but these serve different purposes...

Sign up to request clarification or add additional context in comments.

1 Comment

:( maybe something in the internals area?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.