Assign returning value from 'Typeof Operator' to 'Type' variable : typeof « Operator « C# / CSharp Tutorial






using System;
using System.Reflection;

class MyClass
{
   public int Field1;
   public int Field2;
   public void Method1() { }
   public int  Method2() { return 1; }
}

class MainClass
{
   static void Main()
   {
      Type t = typeof(MyClass);
      FieldInfo[] fi = t.GetFields();

      foreach (FieldInfo f in fi)
         Console.WriteLine("Field : {0}", f.Name);

   }
}
We have a SomeClass object here








3.16.typeof
3.16.1.Using typeof
3.16.2.Demonstrate typeof
3.16.3.typeof a Class name
3.16.4.Using typeof operator in if statement
3.16.5.Obtain type information using the typeof operator
3.16.6.Assign returning value from 'Typeof Operator' to 'Type' variable