Get MemberTypes for a field in CSharp
Description
The following code shows how to get MemberTypes for a field.
Example
//w ww . j a va 2 s. c o m
using System;
using System.Reflection;
public class Myfield
{
private string field = "a private field";
public string Field
{
get{return field;}
}
}
public class Myfieldinfo
{
public static int Main()
{
Myfield Myfield = new Myfield();
Type MyType = typeof(Myfield);
FieldInfo Myfieldinfo = MyType.GetField("field", BindingFlags.NonPublic|BindingFlags.Instance);
MemberTypes Mymembertypes = Myfieldinfo.MemberType;
Console.Write("MemberType is a {0}.", Mymembertypes.ToString());
return 0;
}
}
The code above generates the following result.