8.14. Type Information Operators

The type information operators are used to get the type of the object at runtime. Because all objects inherit from the class System.Object, they all inherit the GetType method, which returns the type of the object. Java has one instanceof operator that you can use to check whether a particular object is an instance of a particular class. C# has operators that are the equivalent of Java's instanceof.

8.14.1. The is Operator

The is operator is used to check whether the runtime type of an object is compatible with a given type. The is operator is used in an expression of the following form:

expr is type

Here, expr is an expression of reference type. The is operator evaluates to true if both of the following conditions ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.