Retrieves the Type of this field.
[Visual Basic] MustOverride Public ReadOnly Property FieldType As Type [C#] public Type FieldType {abstract get;} [C++] public: __property virtual Type* get_FieldType() = 0; [JScript] public abstract function get FieldType() : Type;
Read-only. Retrieves the class of this field object.
The Type is string, Boolean, Integer, and so on.
To get the FieldType property, first get the class Type. From the Type, get the FieldInfo. From the FieldInfo, get the FieldType value.
[C#]
//Make a field public class Myfield { private string field = "private field"; public string Field{ get{return field;} } } public class Myfieldinfo { public static int Main() { Console.WriteLine ("\nReflection.FieldInfo"); Myfield Myfield = new Myfield(); //Get the Type and FieldInfo Type MyType = Type.GetType("Myfield"); FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.NonPublic); //Get and Display the FieldType Console.Write ("\n{0}.", MyType.FullName); Console.Write ("{0} - ", Myfieldinfo.Name); Console.Write ("{0};", Myfield.Field); Console.Write ("\nFieldType = {0}", Myfieldinfo.FieldType); return 0; } }
This code produces the following output:
Myfield.field- private field;
FieldType = System.String
FieldInfo Class | FieldInfo Members | System.Reflection Namespace | FieldAttributes