Tag: null check

为什么String.Equals(Object obj)检查这是否== null?

可能重复: 为什么检查这个!= null? // 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, […]

检查null的性能损失

任何人都可以告诉我在c#中检查对象的对象或属性是否为null的性能成本是多少? 我正在开发一个ASP.NET MVC应用程序,在模型中进行空检查,然后在视图中再次完成。 我觉得这是过度的但是如果没有真正的性能打击那么我就不会看到以这种方式做事的伤害。