Difference between typeof and Type.GetType
Interview question and answer by: Ddd
| Posted on: 3/7/2011 | Category: C# Interview questions
| Views: 2650 | | Points: 40
typeof and Type.GetType both help us to get Type Information using Reflection.
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);
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");
| Alert Moderator
Found interesting? Add this to: