Field Type

In this chapter you will learn:

  1. How to get the field type

Get the field type

FieldInfo.FieldType Property gets the type of this field object.

using System;//from   j av a  2s .com
using System.Reflection;

public class Myfield
{
    private string field = "private field";
}

public class Myfieldinfo
{
    public static int Main()
    {
        Myfield Myfield = new Myfield();
        Type MyType = typeof(Myfield);
        FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.Instance|BindingFlags.NonPublic);
        Console.Write ("\n{0}.", MyType.FullName);
        Console.Write ("{0} - ", Myfieldinfo.Name);
        Console.Write ("{0};", Myfieldinfo.GetValue(Myfield));
        Console.Write ("\nFieldType = {0}", Myfieldinfo.FieldType);
    return 0;
    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to access Field Attributes
Home » C# Tutorial » Reflection
Reflection
Type
Type properties
Field reflection
Field Type
Field Attributes
FieldHandle
Field value
Set Field value
delegate reflection
Event reflection
Indexer reflection
Properties Reflection
Method
Parameter
Invoke
Type Instantiating
interface reflection
Generic type reflection
Reflection on nested Types
Subtype
Array reflection
Assembly