Difference between typeof and Type.GetType

 Posted by Ddd on 3/7/2011 | Category: C# Interview questions | Views: 5480 | Points: 40
Answer:

typeof and Type.GetType both help us to get Type Information using Reflection.

Differences:

typeof:

1)typeof expects only an existent typename.

2)Namespace reference is not needed.

3)typename is verified at the compile time itself

ex: Type t=typeof(Program);

Type.GetType

1))we have to specify a typename, which will be checked at runtime only.
if it does not exist, an exception will be generated.

2)Namespace is needed before the type name

ex: Type t=Type.GetType("System.String");


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response