Atulya Panda
Write the difference between TypeOf and GetType?
Posted by Atulya Panda in C# Language on Nov 26, 2012
  • 0
  • 3
  • 3392
Do you know the answer for this question? Post it below.
Guest
Posted by manju lata yadav on Jul 09, 2014
  • 0

TypeOf:- is an operator to obtain a type known at compile-time (or at least a generic type parameter). The operand of typeof is always the name of a type or type parameter - never an expression with a value (e.g. a variable).
Used to obtain the System.Type object for a type. A typeof expression takes the following form:
System.Type type = typeof(int);

GetType():-GetType() is a method you call on individual objects, to get the execution-time type of the object.

Gets the Type of the current instance.
The exact runtime type of the current instance.
int i = 0;
System.Type type = i.GetType();

Posted by Manoj Kumar on Nov 29, 2012
  • 0

typeof is used to get the type based on a class. That means
if you use typeof with object, it will gives you error. You
must pass class as parameter parameter.
Where GetType is used to get the type based on an object
(an instance of a class). Means GetType needs parameter of
object rather than class name.

Posted by Atulya Panda on Nov 26, 2012
  • 0

Both of them produce the same information. The difference lies that from where the information is got. typeOf is used to get the type based on class. It will give an error if typeOf is used with the object. GetType is used get the type based on object, which states that geType needs parameter of object.


Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS

PRIVACY POLICY | TERMS & CONDITIONS | SITEMAP | CONTACT US | ABOUT US | REPORT ABUSE
2014© C# Corner. All contents are copyright of their authors.