Loop Through LINQ Query Columns (Not rows)

前端 未结 3 1142
我寻月下人不归
我寻月下人不归 2021-01-18 22:01

Is it possible, and if so how, to loop though the results of a LINQ query?

Something like this:

var results= from a in dt.AsEnumerable()
                     


        
3条回答
  •  旧时难觅i
    2021-01-18 22:15

    Action processColumName = (cname) => 
                               { 
                                  // do anything you want with a column name
                                  string foo = (string) Row[cname]; 
                               };
    
    results.First()
            .GetType()
            .GetProperties()
            .Select(p => p.Name)
            .ToList().ForEach(processColumName);
    

提交回复
热议问题