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.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| MethodAccessException | This member is invoked late-bound through mechanisms such as Type.InvokeMember. |
The following example creates a field, gets its FieldInfo, and displays its FieldType.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
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 */
Show:
Note: