2014-02-27 43 views
0
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什麼類型是由查詢表達式創建的對象?

+0

我建議你閱讀一下:http://msdn.microsoft.com/en-us/library/bb308959.aspx HTTP ://msdn.microsoft.com/en-us/library/bb397676.aspx –

回答

3

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(); 
+1

注意:c(僅查詢)是一種懶惰評估器,僅在迭代時才執行。 :) –

0

c是類型IEnumerable<int> 的對象,但它可能是一個列表或任何其他集合。

無參照,反正

PS:謝謝abatishchev

+0

使用'突出顯示代碼,例如'IEnumerable ' – abatishchev

+0

'IEnumerable'和'System.Linq.Enumerable'有什麼區別嗎? – FSou1

+0

我認爲,正確答案是:c是'System.Linq.Enumerable',它實現了'IEnumerable ' – FSou1

相關問題