我對如何從C#查找結構中獲取價值感興趣。從C#查詢中獲取價值
實施例:
var myLookup = (Lookup<string, int>)data.Rows.Cast<DataRow>().ToLookup(row => row["Name"], row => row["Id"]);
foreach (var myLookupItem in myLookup)
{
Debug.WriteLine("Name: " + myLookupItem.Key);
Debug.WriteLine("Id: " + myLookupItem.ToString());
}
問題是
myLookupItem.ToString()
不顯示實際值,而不是僅System.Linq.Lookup2[System.String,System.Int32]
顯示。
後來,我應該使用lambda得到查找值:
int lookupValue = myLookup.Where(x => x.Key == "Test").Select(x => x).FirstOrDefault());
,但是這也給上述相同。
請告知如何實現此目的。
在此先感謝。
不可思議......! –