Get a FieldInfo for the field represented by the specified handle in CSharp

Description

The following code shows how to get a FieldInfo for the field represented by the specified handle.

Example


using System;/*from   w  w  w. jav a  2 s  . com*/
using System.Reflection;

public class FieldInfo_GetFieldFromHandle
{
    public string x;
    public char y;
    public float a;
    public int b;

    public static void Main()
    {
        Type myType = typeof(FieldInfo_GetFieldFromHandle);
        FieldInfo [] myFieldInfoArray = myType.GetFields();
        RuntimeFieldHandle myRuntimeFieldHandle;
        for(int i = 0; i < myFieldInfoArray.Length; i++)
        {
            myRuntimeFieldHandle = myFieldInfoArray[i].FieldHandle;
            FieldInfo myFieldInfo = FieldInfo.GetFieldFromHandle(myRuntimeFieldHandle);
            Console.WriteLine(myFieldInfo);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type