Get all fields from a Type : Field : Reflection C# Examples


C# Examples » Reflection » Field »

 

Get all fields from a Type









    
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);

      }
}
    
   
  
   



Output

Field : Field1
Field : Field2


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Reflection
» Field