List<int> b = new List<int>() { 12, 56, 45, 65, 4, 6 };
b.Add(125);
IEnumerable<int> c = from n in b
where n < 60 && n > 12
select n;
是c
只引用?什麼類型是from ... select n
?什麼類型是由查詢表達式創建的對象?
List<int> b = new List<int>() { 12, 56, 45, 65, 4, 6 };
b.Add(125);
IEnumerable<int> c = from n in b
where n < 60 && n > 12
select n;
是c
只引用?什麼類型是from ... select n
?什麼類型是由查詢表達式創建的對象?
c是類型:
System.Linq.Enumerable+WhereListIterator`1[System.Int32]
可以通過檢查c.GetType看到這個();
如果你希望它是評估,變成了一個「實際」列表中,你可以嘗試:
IEnumerable<int> c = (from n in b where n < 60 && n > 12 select n).ToList();
注意:c(僅查詢)是一種懶惰評估器,僅在迭代時才執行。 :) –
c是類型IEnumerable<int>
的對象,但它可能是一個列表或任何其他集合。
無參照,反正
PS:謝謝abatishchev
使用'突出顯示代碼,例如'IEnumerable
'IEnumerable'和'System.Linq.Enumerable'有什麼區別嗎? – FSou1
我認爲,正確答案是:c是'System.Linq.Enumerable',它實現了'IEnumerable
我建議你閱讀一下:http://msdn.microsoft.com/en-us/library/bb308959.aspx HTTP ://msdn.microsoft.com/en-us/library/bb397676.aspx –