码迷,mamicode.com
首页 > 其他好文 > 详细

Object.ReferenceEquals

时间:2015-12-24 19:13:40      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

https://msdn.microsoft.com/en-us/library/system.object.referenceequals(v=vs.110).aspx

 

However, the return value of the ReferenceEquals method may appear to be anomalous in these two scenarios:

 

1. When comparing value types. If objA and objB are value types, they are boxed before they are passed to the ReferenceEquals method. This means that if both objA and objB represent the same instance of a value type, the ReferenceEquals method nevertheless returns false, as the following example shows.

 

2. When comparing strings. If objA and objB are strings, the ReferenceEquals method returns true if the string is interned. It does not perform a test for value equality. In the following example, s1 and s2 are equal because they are two instances of a single interned string. However, s3 and s4 are not equal, because although they are have identical string values, that string is not interned.

Object.ReferenceEquals

标签:

原文地址:http://www.cnblogs.com/lilei9110/p/5073864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!