documentation for the keyword “is”指出:
The is operator only considers reference conversions,Boxing
conversions,and unBoxing conversions. Other conversions,such as
user-defined conversions,are not considered.
在实践中意味着什么?
用它来检查结构是否是某种类型是错误的吗?
例如,
public struct Point2D { public int X; public int Y; ... public override bool Equals(Object value) { if (value != null && value is Point2D) // or if (value != null && GetType() == value.GetType()) { Point2D right = (Point2D)value; return (X == right.X && Y == right.Y); } else return false; } ... }