Iterate data in anonymous variable
I have a DataTable containing some data, and I am going to fetch some data from it using Linq to datatable.
The query looks like this:
开发者_C百科var requiredData=dt.AsEnumerable()
.Where(row => row.Field<byte>("id") == 1)
.Select(x=> {
id = x.Field<int>("id"),
YYYYY = x.Field<string>("ColumnName2"),
ZZZZZ = x.Field<string>("ColumnName3")
}
);
Now, Please how do I iterate-through "requiredData"?
You could use a foreach loop:
foreach (var item in requiredData)
{
// TODO: use item.id, item.YYYYY and item.ZZZZZ here
}
精彩评论