FieldType Property

FieldInfo.FieldType Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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.

ExceptionCondition
MethodAccessException

This member is invoked late-bound through mechanisms such as Type.InvokeMember.

The type is a 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 FieldInfo, and displays its FieldType.


using System;
using System.Reflection;

public class Example
{
   public string SomeField = "field value";

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      Example ex = new Example();

      // Get the type and FieldInfo.
      Type MyType = typeof(Example);
      FieldInfo fi = MyType.GetField("SomeField",
          BindingFlags.Instance | BindingFlags.Public);

      // Get and display the name, value, and FieldType.
      outputBlock.Text += String.Format("{0}.{1}: \"{2}\"\n", MyType.FullName,
         fi.Name, fi.GetValue(ex));
      outputBlock.Text += String.Format("FieldType = {0}\n", fi.FieldType);
   }
}

/* This code produces the following output:

Example.SomeField: "field value"
FieldType = System.String
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft