#577 – Using the is Operator to Check for an Unboxing Conversion
May 7, 2012 Leave a comment
You can use the is operator to check to see whether an object can be unboxed to a particular type. The operator will return true if the object contains a boxed instance of the specified type.
int i = 12; double d1 = 4.2; object o1 = i; // Boxed int object o2 = d1; // Boxed double object o3 = new object(); // Some object bool check; check = o1 is int; // true - object contains a boxed int check = o2 is int; // false - object contains boxed double check = o3 is int; // false