Saturday, 17 December 2016

Typeof() vs GetType()

if you want to obtain the type from an instance of your class,you can use GetType().

GetType() returns run time type of the instance.

if you don't have an instance,but you know the type name,you would use typeof().

TypeOf() gives the compile time of class.

Note :
Operator TypeOf(ClassName) is used to obtain the System.Type object for a Type at compile time.

MyObject.GetType() is used to obtain the exact run time type of object.This method uses reflection.

No comments:

Post a Comment