UIntPtr.Zero 字段


表示已初始化为零的指针或句柄的只读字段。A read-only field that represents a pointer or handle that has been initialized to zero.

public: static initonly UIntPtr Zero;
public static readonly UIntPtr Zero;
 staticval mutable Zero : unativeint
Public Shared ReadOnly Zero As UIntPtr 




此字段的值与不等效 nullThe value of this field is not equivalent to null. 使用此字段有效地确定的实例是否已 UIntPtr 设置为非零值。Use this field to efficiently determine whether an instance of UIntPtr has been set to a value other than zero.

例如,假设变量 uip 为的实例 UIntPtrFor example, assume the variable, uip, is an instance of UIntPtr. 您可以通过将它与构造函数返回的值进行比较来确定是否已对其进行设置,例如 if uip != new UIntPtr(0)...You can determine if it has been set by comparing it to the value returned by a constructor, for example, if uip != new UIntPtr(0).... 但是,调用构造函数以获取未初始化的指针是低效的。However, invoking a constructor to get an uninitialized pointer is inefficient. 更好的做法是编写 if uip != UIntPtr.Zero... 或代码 if !UIntPtr.Zero.Equals(uip)...It is better to code either if uip != UIntPtr.Zero... or if !UIntPtr.Zero.Equals(uip)....