The "is" Keyword and Equals Method Override

The documentation for the keyword is states that:

The is operator only considers links, conversion boxing and conversion unboxing. Other conversions, such as user-defined conversions, are not considered.

What does this mean in practice? Is it wrong to use it to check if a structure is a specific 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; } ... } 
+7
source share
1 answer

Validation of the structure of a certain type. Documentation means that user-defined conversion operators and implicit ones are not evaluated when considering whether a given object is of a specified type, even if there is a user-defined operator that can convert it to the specified type.

+6
source

All Articles