C# FieldInfo FieldType

Description

FieldInfo FieldType Gets the type of this field object.

Syntax

FieldInfo.FieldType has the following syntax.


public abstract Type FieldType { get; }

Example

The following example creates a field, gets its type and FieldInfo, and displays its FieldType.


//  w w w. j  av a2 s  .  c  o  m

using System;
using System.Reflection;
public class Myfield
{
    private string field = "private field";
}

public class Myfieldinfo
{
    public static int Main()
    {
        Myfield Myfield = new Myfield();
        Type MyType = typeof(Myfield);
        FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);

        Console.Write ("\n{0}.", MyType.FullName);
        Console.Write ("{0} - ", Myfieldinfo.Name);
        Console.Write ("{0};", Myfieldinfo.GetValue(Myfield));
        Console.Write ("\nFieldType = {0}", Myfieldinfo.FieldType);
        return 0;
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo