C# TypeInfo GetFields()

Description

TypeInfo GetFields() Returns all the public fields of the current Type.

Syntax

TypeInfo.GetFields() has the following syntax.


public FieldInfo[] GetFields()

Returns

TypeInfo.GetFields() method returns

Example

The following example shows a use of the GetFields() method.


//w ww  .j a  v a 2 s . c o m
using System;
using System.Reflection;
using System.ComponentModel.Design;


class FieldInfo_IsSpecialName
{
    public static void Main()
    {     
        Type myType = typeof(ViewTechnology);
        FieldInfo[] myField = myType.GetFields();

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo