How should i use linq to sort my data when my data contain both numbers and letters?
For example my current 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)
returns something like the following
13
167
172
231
44
49
which is not what i would like it to be…
The output should be like the one below
13
44
49
167
172
231
Any ideas?
Thank you for your time
Don’t use the
Valueproperty ofXAttribute– use the explicit conversion toInteger. I think this should do it:Note that it’s generally a better idea to use the explicit conversions supported by
XAttributeandXElementthan to useInt32.Parseetc, as then the XML-specific parsing will be performed, following the appropriate standard formats.