开发者

What is a ".Net Identity"?

I have seen this sentence in one book:

"Default implementation of Equals(), defined by System.Object, which uses a comparison by .NET identity."

Does .Net Identity mean the memory address allocated in the memory for both for refernce type开发者_JS百科s and value types?


From MSDN:

The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.

Does it answer your question?


In this case, check out the official documentation.

http://msdn.microsoft.com/en-us/library/bsc2ak47(v=vs.80).aspx

The default implementation of Equals supports reference equality only, but derived classes can override this method to support value equality.

For reference types, equality is defined as object equality; that is, whether the references refer to the same object. For value types, equality is defined as bitwise equality. The ValueType class supports value types.

So for reference types, unless they override Equals, the reference is compared - i.e. "does this refer to the same object". For value types, the entire value is compared.


Two instances of a class are "identical" if they are actually the same instance (same memory location).
The default implementation IMHO calls Object.ReferenceEquals.

Two structures are "identical" if their values are all equal meaning they are bitwise identical.
The default implementation here uses refletion to compare all members IMHO.

However, both behaviors can be overriden using the Equals method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜