C# Type GetFields()

Description

Type GetFields() returns all the public fields of the current Type.

Syntax

Type.GetFields() has the following syntax.


public FieldInfo[] GetFields()

Returns

Type.GetFields() method returns

Example

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


/*from   w ww. ja va 2  s .  c  om*/
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 »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version