Partager via


FieldInfo.FieldType Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the type of this field object.

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

Syntax

'Declaration
Public MustOverride ReadOnly Property FieldType As Type
public abstract Type FieldType { get; }

Property Value

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

Exceptions

Exception Condition
MethodAccessException

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

Remarks

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.

Examples

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

Imports System.Reflection

Public Class Example

   Public SomeField As String = "field value"

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 
      Dim ex As New Example()

      ' Get the type and FieldInfo.
      Dim MyType As Type = GetType(Example)
      Dim fi As FieldInfo = MyType.GetField("SomeField", _
          BindingFlags.Instance Or BindingFlags.Public)

      ' Get and display the name, value, and FieldType.
      outputBlock.Text &= String.Format("{0}.{1}: ""{2}""", MyType.Name, _
          fi.Name, fi.GetValue(ex)) & vbCrLf
      outputBlock.Text &= String.Format("FieldType = {0}", fi.FieldType) & vbCrLf

   End Sub
End Class 

' This code produces the following output:
'
'Example.SomeField: "field value"
'FieldType = System.String
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
 */

Version Information

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

Platforms

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