標籤: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子句