日期:2014-05-18  浏览次数:20775 次

C#中如何获取一个类中的每个字段(用反射)
public class PixBean
  {
  private string pixName;

   
   
  private string pixDerict;

   
  private string pixMostlyMan;

  private string pixType;

  public string PixType
   
  private ArrayList pixTime;

   

   
  private int pixPrice;

  public int PixPrice
   
  private int pixRebate;

   
  private string pixPictruePath;
希望获得(pixName,pixDerict.....)

 

------解决方案--------------------
C# code

            Type t = typeof(PixBean);
            FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            foreach (FieldInfo fi in fields)
                Console.WriteLine(fi.Name);
/*
输出:
pixName
pixDerict
pixMostlyMan
pixType
pixTime
pixPrice
pixRebate
pixPictruePath
*/

------解决方案--------------------
探讨
FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
解释一下这句话