The documentation for the keyword "is" states that:
The is operator only considers reference conversions, boxing conversions, and unboxing conversions. Other conversions, such as user-defined conversions, are not considered.
What does it mean in practice? Is it wrong to use it to check if a struct is a certain type? For example,
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;
}
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.