<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 如何:從方法中返回查詢(C# 編程指南) 此示例演示如何從某一方法以返回值和 **out** 參數的形式返回查詢。 任何查詢的類型都必須為 [IEnumerable](https://msdn.microsoft.com/zh-cn/library/system.collections.ienumerable.aspx) 或 [IEnumerable&lt;T&gt;](https://msdn.microsoft.com/zh-cn/library/9eekhta0.aspx),或一種派生類型(如 [IQueryable&lt;T&gt;](https://msdn.microsoft.com/zh-cn/library/bb351562.aspx))。因此,返回查詢的方法的任何返回值或 **out** 參數也必須具有該類型。如果某個方法將查詢具體化為具體的 [List&lt;T&gt;](https://msdn.microsoft.com/zh-cn/library/6sh2ey19.aspx) 或 [Array](https://msdn.microsoft.com/zh-cn/library/system.array.aspx) 類型,則認為該方法在返回查詢結果(而不是查詢本身)。仍然能夠編寫或修改從方法返回的查詢變量。 在下面的示例中,第一個方法以返回值的形式返回查詢,第二個方法以 **out** 參數的形式返回查詢。請注意,在這兩種情況下,返回的都是查詢,而不是查詢結果。 ``` class MQ { // QueryMethhod1 returns a query as its value. IEnumerable<string> QueryMethod1(ref int[] ints) { var intsToStrings = from i in ints where i > 4 select i.ToString(); return intsToStrings; } // QueryMethod2 returns a query as the value of parameter returnQ. void QueryMethod2(ref int[] ints, out IEnumerable<string> returnQ) { var intsToStrings = from i in ints where i < 4 select i.ToString(); returnQ = intsToStrings; } static void Main() { MQ app = new MQ(); int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // QueryMethod1 returns a query as the value of the method. var myQuery1 = app.QueryMethod1(ref nums); // Query myQuery1 is executed in the following foreach loop. Console.WriteLine("Results of executing myQuery1:"); // Rest the mouse pointer over myQuery1 to see its type. foreach (string s in myQuery1) { Console.WriteLine(s); } // You also can execute the query returned from QueryMethod1 // directly, without using myQuery1. Console.WriteLine("\nResults of executing myQuery1 directly:"); // Rest the mouse pointer over the call to QueryMethod1 to see its // return type. foreach (string s in app.QueryMethod1(ref nums)) { Console.WriteLine(s); } IEnumerable<string> myQuery2; // QueryMethod2 returns a query as the value of its out parameter. app.QueryMethod2(ref nums, out myQuery2); // Execute the returned query. Console.WriteLine("\nResults of executing myQuery2:"); foreach (string s in myQuery2) { Console.WriteLine(s); } // You can modify a query by using query composition. A saved query // is nested inside a new query definition that revises the results // of the first query. myQuery1 = from item in myQuery1 orderby item descending select item; // Execute the modified query. Console.WriteLine("\nResults of executing modified myQuery1:"); foreach (string s in myQuery1) { Console.WriteLine(s); } // Keep console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } ``` ## 編譯代碼 * 創建面向 .NET Framework 3.5 或更高版本的 Visual Studio?項目。默認情況下,該項目具有一個對 System.Core.dll 的引用以及一條針對 System.Linq 命名空間的 **using** 指令。 * 將類替換為示例中的代碼。 * 按 F5 編譯并運行程序。 * 按任意鍵退出控制臺窗口。 ## 請參閱 [LINQ 查詢表達式(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/bb397676.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看