C# into子句

來源:互聯網
上載者:User

標籤:microsoft   select   hat   div   ora   void   note   mod   sof   

可使用 into 內容關鍵字建立臨時標識符,將 group、join 或 select 子句的結果儲存至新標識符。 此標識符本身可以是附加查詢命令的產生器。 有時稱在 group 或 select 子句中使用新標識符為“延續”。

樣本

下面的樣本示範使用 into 關鍵字來啟用具有推斷類型 IGrouping 的臨時標識符 fruitGroup。 通過使用該標識符,可對每個組調用 Count 方法,並且僅選擇那些包含兩個或更多個單詞的組。

class IntoSample1{    static void Main()    {                // Create a data source.        string[] words = { "apples", "blueberries", "oranges", "bananas", "apricots"};        // Create the query.        var wordGroups1 =            from w in words            group w by w[0] into fruitGroup            where fruitGroup.Count() >= 2            select new { FirstLetter = fruitGroup.Key, Words = fruitGroup.Count() };        // Execute the query. Note that we only iterate over the groups,         // not the items in each group        foreach (var item in wordGroups1)        {            Console.WriteLine(" {0} has {1} elements.", item.FirstLetter, item.Words);        }        // Keep the console window open in debug mode        Console.WriteLine("Press any key to exit.");        Console.ReadKey();    }}/* Output:   a has 2 elements.   b has 2 elements.*/

 

C# into子句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.