回傳序列元素 (Select Many)

使用兩個From , 達到 SelectMany的效果。

 //寫法2:SelectMany

            WriteLine("=寫法2=");

            IEnumerable<string> words2 = sentence.SelectMany(segment => segment.Split(' '));

            foreach (string w in words2)

            {

                WriteLine(w);

            }

//寫法3:用查詢表達式,達到寫法2-SelectMany的效果,我比較喜歡寫法3

            WriteLine("=寫法3=");

            IEnumerable<string> words3 =

                from segment in sentence

                from w in segment.Split(' ')

                select w;

            foreach (string w in words3)

            {

                WriteLine(w);

            }

留言

這個網誌中的熱門文章

溪和食品有限公司 - 觀光工廠接待人員(薪約30K.免費供餐),今天投遞此份工作。

載入JavaScript code的最佳時機