看板 C_Sharp 關於我們 聯絡資訊
小弟最近在研讀LINQ及Lamdba 有個點一直想不通。 因為我是邊看書邊學... 在書的開頭提到可以使用from where select去查詢集合內的資料 例如: List<string> temp = new <string> { "Mon","Tue","Wed","Thi","Fri","Sat","Sun" }; 可以透過 IEnumerable<string> test = from str in temp where str.StartWith("T") select 取得所需要的資料。 但是,在第二、三張的又介紹了GetEnumator這個列舉器。 這個的作用也是逐一地去查詢集合中的每一個元素... 那麼跟上述的from where select 有什麼差異呢?? 什麼時候會用到from where select ? 甚麼時候又會用到 IEnumable的 GetEnumator呢?? 麻煩各位前輩指點迷津 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.173.145.79 ※ 文章網址: http://www.ptt.cc/bbs/C_Sharp/M.1415106301.A.95C.html
O187: 好開發,增加可讀性 11/04 21:17
SmartGoose: LINQ底層應該也是用IEnumable,你就不用自已去操作 11/04 23:17
SmartGoose: IEnumable 11/04 23:18
deuter: 你可以試試看把上面的程式用 GetEnumerator 寫出來 11/05 12:19
deuter: 比較看看, 就知道差在哪裡了 11/05 12:20
don750421: 是因為foreach底層在也是會實作Enumable嗎?? 11/05 21:23
don750421: 所以,書上才會列出這部分讓讀者參考? 11/05 21:24
moremore1234: 你可以看msdn上寫的http://ppt.cc/JQ4Q 11/05 23:10