I'm having a list which has some versions in it .
sample data :
"4.5","2.1","2.2.1","7.5","7.5.3","N/A","2.3.4.5"
As you can see the data , i'm trying to sort list by Descending tough 3.8.5 is invalidnumber & NA is a invalid one .
Code :
decimal result;
var sortedVData = vData.OrderByDescending(v => decimal.TryParse(v.vCode, out result) ? Convert.ToDecimal(v.vCode) : decimal.MaxValue);
Output : "NA" , "7.5.3" , '2.3.4.5' , "2.2.1" , '7.5' , '4.5' , '2.1'
As you see in my else(:) condition i'm doing decimal.MaxValue to make NA to come top if there is invalid value (any string with text) but 2.2.1 should be a exception and should work as number(tough 2.2.1 or any number having multiple decimals a is invalid in version's point of view i want them made conditionally valid .
Expected Result : "NA" , "7.5.3" , "7.5" , "4.5" ,"2.3.4.5" ,"2.2.1" , "2.1"