Mega Code Archive

 
Categories / C# / Reflection
 

Demonstrates both the instance and static GetType methods

using System; class MyClass<K, V> {     public void FunctionA(K argk, V argv) {     } } class XClass<T> {     public void FunctionB(T argt) {     } } class Starter {     public static void Main() {         MyClass<int, decimal> obj = new MyClass<int, decimal>();         Type typeClosed = obj.GetType();         Console.WriteLine(typeClosed.ToString());         Type typeOpen = Type.GetType("CSharpBook.XClass`1");         Console.WriteLine(typeOpen.ToString());         Type typeClosed2 = Type.GetType(             "CSharpBook.MyClass`2[System.Int32, System.Decimal]");         Console.WriteLine(typeClosed2.ToString());     } }