A summary of the differences between is and as operators in C

  • 2020-12-16 06:05:32
  • OfStack

1. is verifies that the operation object is what it wants

Operation formula: object is type

Returns true: The object is of the specified type

Returns false: The object is not of the specified type

as converts an object to a specified type

Operation formula: object as type

Conversion successful: the type of the object is the specified type

Conversion failed: return null

Note: The "is" and "as" operator be used with reference reference or nullable type (example: 'int' is a value type)


Related articles: