One, C # is operator
The IS operator is used to check whether an object is compatible with a given type (compatible means that the object is that type, or is derived from that type).
The IS operator is used to check whether an object (variable) belongs to a data type, such as int, string, bool, double, class, and so on. It can be used before the type-safe conversion.
The rules for the IS operator are as follows:
Returns True if the object is compatible with the given type, or False if the object is incompatible with the given type.
? No exception is thrown.
If the object is null, the return value is always false.
Ii. examples
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Test
{
Class Program
{
static void Main (string[] args)
{
C # is operator-www.baike369.com
int x = 5;
if (x is Object)
{
Console.WriteLine ("X is an object.");
}
Console.ReadLine ();
}
}
}
Operation Result:
X is an object.
Note: int and C # Other data types are inherited from object. Please read the C # object type.
C # is operator