Get all the public fields of the current Type in CSharp

Description

The following code shows how to get all the public fields of the current Type.

Example


//  w  w  w .ja v  a  2s  . co m
using System;
using System.Reflection;
using System.ComponentModel.Design;


class FieldInfo_IsSpecialName
{
    public static void Main()
    {     
        Type myType = Type.GetType("System.String");
        FieldInfo[] myField = myType.GetFields();

        for(int i = 0; i < myField.Length; i++)
        {
            if(myField[i].IsSpecialName)
            {
                Console.WriteLine(myField[i].Name);
            }
        }
    }
}




















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type