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.

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
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft