遍历具有动态类型的列表

时间:2011-09-12 07:37:41

标签: asp.net dynamic

从linq查询中获取List<dynamic>对象后,我想使用以下技术遍历每个元素。它不起作用,可能是什么原因?

IEnumerable<dynamic> lstPhysicianMeasures =
    (from pmc in y
     select new
     {
         MeasureId = pmc.PK_PRIMARY_KEY,
         Title = pmc.TITLE,
         MeasureCode = pmc.MEASURE_CODE,
         MinAge = pmc.MIN_AGE ?? 0,
         MaxAge = pmc.MAX_AGE ?? 0,
         Description = pmc.DESCRIPTION ?? string.Empty,
         IS_SELECTED = ((System.Boolean?)pmc.IS_ACTIVE ?? false)
      }).ToList();

foreach (dynamic objMeasure in lstPhysicianMeasures)
{
    var gMeasureCode = objMeasure.MeasureCode;
}

由于

1 个答案:

答案 0 :(得分:0)

尝试使用var而不是dynamic。