I want to make the following query dynamic.
var t = from r in dt.AsEnumerable()
orderby r.Field< int >("id") ascending
select r;
void query(string sorttype,string sortorder)
Is it possbile to change the order by part so that those paramater will come from parameters of a function like so开发者_运维问答rttype for id in here and sortorder for ascending.
I think this ought to do it:
IEnumerable query<sorttype>(DataTable dt, string sortorder) {
return dt.GetList().OrderBy(row => row.Field<sorttype>(sortorder));
}
Note that sorttype is a generic type parameter, not a string.
精彩评论