Do you mean something like this?:
List<string> empname = dtMain.AsEnumerable()
.Where(a => a.Field<decimal>("Salary") > 2500)
.Select(a => new {
ID = a.Field<int>("ID"),
Name = a.Field<string>("Name"),
Salary = a.Field<decimal>("Salary")
});
A .Select()
shouldn't have side-effects, i.e. it shouldn't be editing the state of your program from inside the function you pass it. It should just map from one value to another and that's it.
In the snippet above the if
statement is moved out of the mapping function and into a .Where()
which configures a predicate/filter, which will be use to exclude items that don't satisfy the condition (i.e. if the Salary
isn't 2500+)