訂購輸出

Dim sites() As String = {"Stack Overflow", 
                         "Super User", 
                         "Ask Ubuntu", 
                         "Hardware Recommendations"}

Dim query = From x In sites 
            Order By x.Length

' result = "Super User", "Ask Ubuntu", "Stack Overflow", "Hardware Recommendations"

OrderBy 子句通過子句返回的值對輸出進行排序。在此示例中,它是每個字串的長度。預設輸出順序為升序。如果需要降序,可以指定 Descending 關鍵字後子句。

Dim query = From x In sites
            Order By x.Length Descending