Export (0) Print
Expand All

FieldInfo.FieldType Property

Gets the type of this field object.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public abstract Type FieldType { get; }

Property Value

Type: System.Type
The type of this field object.

Implements

_FieldInfo.FieldType

The type is some primitive data type, such as String, Boolean, or GUID.

To get the FieldType property, first get the class Type. From the Type, get the FieldInfo. From the FieldInfo, get the FieldType value.

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

using System;
using System.Reflection;


// Make a field. 
public class Myfield
{
    private string field = "private field";
}

public class Myfieldinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.FieldInfo");
        Myfield Myfield = new Myfield();

        // Get the type and FieldInfo.
        Type MyType = typeof(Myfield);
        FieldInfo Myfieldinfo = MyType.GetField("field", 
            BindingFlags.Instance|BindingFlags.NonPublic);

        // Get and display the FieldType.
        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;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft