动态类型遍历列表
从 linq 查询获取 List
对象后,我想使用以下技术遍历每个元素。它不起作用,可能是什么原因?
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;
}
谢谢
After getting a List<dynamic>
object from the linq query, I want to traverse through each element using the following technique. It's not working, what can be the cause?
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;
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 var 而不是动态。
Try using var instead of dynamic.