當我的數據包含數字和字母時,我應該如何使用linq對數據進行排序?LINQ:排序(將字母當作數字)
例如我現在的LINQ
Dim MyQuery = From c In XDoc.Descendants() _
Where c.Attribute(Y) IsNot Nothing And c.Attribute(Str) IsNot Nothing _
Order By Val(c.Attribute(Y).Value), Val(c.Attribute(X).Value) _
Select Str = c.Attribute(Str)
返回類似下面的
13
167
172
231
44
49
這是不是我想它是... 輸出應該像下面的一個
13
44
49
167
172
231
任何想法? 謝謝你的時間
爲什麼在LINQ to XML已經支持直接轉換爲整數時使用'int.Parse'? –
@Jon - 實際上我在那裏有'int'投射,但是我反對'.Value',我意識到它不會工作,所以我將它改爲'int.Parse()'。我沒有想到顯式轉換爲整數,感謝提醒 - 已編輯。 –
我不確定C#樣式轉換爲'int'將在VB中工作,但... –