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

var salerIncomeList = new List<object>();
var salerIncomeList = new List<object>();  
  var objitem = new
  {
  realname = item.realName,
  username=item.userName,
  commision=income,

  };
  salerIncomeList.Add(objitem);
我如何用foreach遍历 salerIncomeList

还是有其他做objitem集合的方法

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

void Main()
{
    var salerIncomeList = new List<object>();   
  var objitem = new
  {
  realname = "aaa",//item.realName,
  username="bbb",//item.userName,
  commision="ccc"//income,

  };
  salerIncomeList.Add(objitem);
  
  foreach(var obj in salerIncomeList)
  {
  System.Reflection.PropertyInfo propertyInfo=obj.GetType().GetProperty("realname");
  Console.WriteLine(propertyInfo.GetValue(obj,null).ToString());  //aaa
  }
}