【发布时间】:2012-04-27 11:34:46
【问题描述】:
// Determines whether two strings match.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public override bool Equals(Object obj)
{
//this is necessary to guard against reverse-pinvokes and
//other callers who do not use the callvirt instruction
if (this == null)
throw new NullReferenceException();
String str = obj as String;
if (str == null)
return false;
if (Object.ReferenceEquals(this, obj))
return true;
return EqualsHelper(this, str);
}
我不明白的部分是它正在检查当前实例this 是否为空。评论有点混乱,所以我想知道该评论的真正含义是什么?
谁能举例说明如果不存在该检查会如何中断,这是否意味着我也应该将该检查放入我的课程中?
【问题讨论】:
-
@FlorianGreinacher:不可能重复,但几乎完全一样,哈哈。我想知道为什么在我写问题时它没有出现在“相关”中?
标签: c# .net string pinvoke null-check