有個List:
列名: id productName Num
內容: 1 book1 sn25124
2 book2 sn554124
現在想由客戶端 控制,只選擇 id / productName兩個欄位后,如何通過linq查詢出記錄成如下這樣:
id productName
1 book1
2 book2
var listOther = List.select(x=>???)
謝謝
uj5u.com熱心網友回復:
既然要動態分配key,就用Dictionary<string, object>吧var _keys = new List<string> {"id", "productName" };
Dictionary<string, object> dic = new Dictionary<string, object>();
_keys.ForEach(k =>
{
dic[k]= x.GetType().GetProperty(k).GetValue(x);
});
return dic;
uj5u.com熱心網友回復:
有沒有linq的寫法?轉載請註明出處,本文鏈接:https://www.uj5u.com/net/281914.html
標籤:ASP.NET
