Tuesday, May 10, 2011

typeof vs Type.GetType

typeof is resolved at compile time, so the type has to be either in
current assembly or one of the assemblies it reference to. Type.GetType on
the other hand, resolves the full qualified type name (namespace + assembly
information) at runtime, so it can be used to load types defined in any
assembly that can be located at runtime. Another note about Type.GetType is,
when called with a typename without the defining assembly, it only looks for
the type in calling assembly and mscorlib.dll.

No comments:

Post a Comment