<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # orderby 子句(C# 參考) 在查詢表達式中,**orderby** 子句可使返回的序列或子序列(組)按升序或降序排序。可以指定多個鍵,以便執行一個或多個次要排序操作。排序是由針對元素類型的默認比較器執行的。默認排序順序為升序。您還可以指定自定義比較器。但是,只能通過基于方法的語法使用它。有關更多信息,請參見 [Sorting Data](https://msdn.microsoft.com/zh-cn/library/bb546145.aspx)。 在下面的示例中,第一個查詢按從 A 開始的字母順序對單詞進行排序,第二個查詢按降序對相同的單詞進行排序。(**ascending** 關鍵字是默認排序值,可以省略。) ``` class OrderbySample1 { static void Main() { // Create a delicious data source. string[] fruits = { "cherry", "apple", "blueberry" }; // Query for ascending sort. IEnumerable<string> sortAscendingQuery = from fruit in fruits orderby fruit //"ascending" is default select fruit; // Query for descending sort. IEnumerable<string> sortDescendingQuery = from w in fruits orderby w descending select w; // Execute the query. Console.WriteLine("Ascending:"); foreach (string s in sortAscendingQuery) { Console.WriteLine(s); } // Execute the query. Console.WriteLine(Environment.NewLine + "Descending:"); foreach (string s in sortDescendingQuery) { Console.WriteLine(s); } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: Ascending: apple blueberry cherry Descending: cherry blueberry apple */ ``` 下面的示例對學生的姓氏執行主要排序,然后對他們的名字執行次要排序。 ``` class OrderbySample2 { // The element type of the data source. public class Student { public string First { get; set; } public string Last { get; set; } public int ID { get; set; } } public static List<Student> GetStudents() { // Use a collection initializer to create the data source. Note that each element // in the list contains an inner sequence of scores. List<Student> students = new List<Student> { new Student {First="Svetlana", Last="Omelchenko", ID=111}, new Student {First="Claire", Last="O'Donnell", ID=112}, new Student {First="Sven", Last="Mortensen", ID=113}, new Student {First="Cesar", Last="Garcia", ID=114}, new Student {First="Debra", Last="Garcia", ID=115} }; return students; } static void Main(string[] args) { // Create the data source. List<Student> students = GetStudents(); // Create the query. IEnumerable<Student> sortedStudents = from student in students orderby student.Last ascending, student.First ascending select student; // Execute the query. Console.WriteLine("sortedStudents:"); foreach (Student student in sortedStudents) Console.WriteLine(student.Last + " " + student.First); // Now create groups and sort the groups. The query first sorts the names // of all students so that they will be in alphabetical order after they are // grouped. The second orderby sorts the group keys in alpha order. var sortedGroups = from student in students orderby student.Last, student.First group student by student.Last[0] into newGroup orderby newGroup.Key select newGroup; // Execute the query. Console.WriteLine(Environment.NewLine + "sortedGroups:"); foreach (var studentGroup in sortedGroups) { Console.WriteLine(studentGroup.Key); foreach (var student in studentGroup) { Console.WriteLine(" {0}, {1}", student.Last, student.First); } } // Keep the console window open in debug mode Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: sortedStudents: Garcia Cesar Garcia Debra Mortensen Sven O'Donnell Claire Omelchenko Svetlana sortedGroups: G Garcia, Cesar Garcia, Debra M Mortensen, Sven O O'Donnell, Claire Omelchenko, Svetlana */ ``` ## 備注 編譯時,**orderby** 子句被轉換為對 [OrderBy&lt;TSource, TKey&gt;](https://msdn.microsoft.com/zh-cn/library/bb534966.aspx) 方法的調用。 **orderby** 子句中的多個鍵轉換為 [ThenBy&lt;TSource, TKey&gt;](https://msdn.microsoft.com/zh-cn/library/bb534743.aspx) 方法調用。 ## 請參閱 [C# 參考](https://msdn.microsoft.com/zh-cn/library/618ayhy6.aspx) [查詢關鍵字(C# 參考)](https://msdn.microsoft.com/zh-cn/library/bb310804.aspx) [LINQ 查詢表達式(C# 編程指南)](https://msdn.microsoft.com/zh-cn/library/bb397676.aspx) [group 子句(C# 參考)](https://msdn.microsoft.com/zh-cn/library/bb384063.aspx) [Getting Started with LINQ in C#](https://msdn.microsoft.com/zh-cn/library/bb397933.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>

                              哎呀哎呀视频在线观看