typeof() is used to get the type information from a type. Here type can be class, delegate, interface etc.
e.g. Type t = typeof(Employee);
GetType() is used to get the type information from the object.
e.g. var obj = new Employee();
Type t = obj.GetType();
Thus, when you have an object you should use GetType function to extract Type information and when you have only a type with you then you should use typeof() operator to extract type information.
e.g. Type t = typeof(Employee);
GetType() is used to get the type information from the object.
e.g. var obj = new Employee();
Type t = obj.GetType();
Thus, when you have an object you should use GetType function to extract Type information and when you have only a type with you then you should use typeof() operator to extract type information.
Comments
Post a Comment