SoFunction
Updated on 2025-03-06

Summary of the difference between is and as operators in C#

1. is to verify whether the operation object is what you want

Operation formula: Object is type

Return true: The object is the specified type

Return false: The object is not the specified type

2. as is to convert the object to the specified type

Operation formula: object as type

Conversion successfully: The type of the object is the specified type

Conversion failed: Return null

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