本文整理汇总了C#中System.Reflection.FieldInfo类的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo类的具体用法?C# FieldInfo怎么用?C# FieldInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldInfo类属于System.Reflection命名空间,在下文中一共展示了FieldInfo类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Reflection;
public class FieldInfoClass
{
public int myField1 = 0;
protected string myField2 = null;
public static void Main()
{
FieldInfo[] myFieldInfo;
Type myType = typeof(FieldInfoClass);
// Get the type and fields of FieldInfoClass.
myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance
| BindingFlags.Public);
Console.WriteLine("\nThe fields of " +
"FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
for(int i = 0; i < myFieldInfo.Length; i++)
{
Console.WriteLine("\nName : {0}", myFieldInfo[i].Name);
Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].DeclaringType);
Console.WriteLine("IsPublic : {0}", myFieldInfo[i].IsPublic);
Console.WriteLine("MemberType : {0}", myFieldInfo[i].MemberType);
Console.WriteLine("FieldType : {0}", myFieldInfo[i].FieldType);
Console.WriteLine("IsFamily : {0}", myFieldInfo[i].IsFamily);
}
}
}