Mega Code Archive

 
Categories / C# Tutorial / Reflection
 

Get Type with typeof

using System; using System.Reflection; using System.Globalization;   class Class1   {     DateTime[] dateTimes = new DateTime[10];     public DateTime this[int index]     {       get{ return dateTimes[index]; }       set{ dateTimes[index] = value;}     }          private DateTime dateOfBirth;     public DateTime DateOfBirth     {         get{ return dateOfBirth; }         set{ dateOfBirth = value; }     }            public void Test()     {       Console.WriteLine("Test method called");     }          private string field;          public string Property     {        get{ return field; }       set{ field = value; }     }        }     class MainClass{          static void Main(string[] args)     {       Type type = typeof(Class1);       Console.WriteLine(type.FullName);              type = Type.GetType("Class1");       Console.WriteLine(type.Namespace);     }