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
Try using var instead of dynamic.