Type Checking
is Operator
The is operator checks if the run-time type of an expression result is compatible with a given type.
The is operator doesn't consider user-defined conversions.
The Is Operator only returns a boolean value
It can be useful when you want to determine the type but not necessarily cast
Beginning with C# 7.0, the is operator also tests an expression result against a pattern.
Checks if an object is compatible with a given type and always returns a boolean value
An is expression evaluates to true if the provided expression is non-null, and the provided object can be cast to the provided type without causing an exception to be thrown.
You can use the Is operator to test whether a cast can be made successfully
The is operator cannot be overloaded.
If you know the specific base class, then just use the is keyword:
This is a cast parameter ?
string myobject = "";
if (myobject is string)
{
}
if (myobject is int)
{
}
if (myobject is class1)
{
}
Note that the is operator only considers reference conversions, boxing conversions, and unboxing conversions. Other conversions, such as user-defined conversions, are not considered.
You can use the Is and As operators to test whether a cast can be made successfully.
class Dog : Animal {}
void UseIsOperator(Animal a)
if (a is Dog)
{
}
The equivalent in VB.Net is the Is Operator.
typeof Operator
The typeof operator in C# on the other hand returns an instance of the System.Type class containing type declarations of the type you pass to it.
Type t = typeof(string);
This operator returns an instance of the System.Type class containing type declarations of the type you pass to it.
System.Type type = typeof(int);
The typeof operator cannot be overloaded.
The equivalent in VB.Net is the GetType Operator
There is a TypeOf Operator in VB.Net but it has a different meaning - which is extremely confusing.
object.GetType()
Also called GetType Method
Also called the GetType Method
This method operators on an object instance.
System.Type.GetType("System.Int32")
if (control.GetType().Name.Equals("TreeView"))
{ }
switch (myobject.GetType().ToString())
{
case "" : break;
}
object.GetType() // System.Int32
object.GetType().Name // Int32
GetType().Name()
GetType().FullName
The object must be instantiated
This method is also available in VB.Net
Dim sVariable As String
Dim oType As Type = sVariable.GetType()
The equivalent in VB.Net is the TypeName function.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext