Call
1list<string> data =Newlist<string>() {2 "d-001-001-001","a-001-004-001","a-001-002-001",3 "a-002-001-001","f-004-001-001","a-003-001-001",4 "a-004-001-004","a-041-0401-031","" };5 varGF = ( fromEinchDataSelecte). (x = x,NewAlphanumericcomparer ()). ToList ();
Comparator
1 Public classalphanumericcomparer:icomparer<string>2 {3 Public intCompare (stringFirststringsecond)4 {5 intFirstnumber, Secondnumber;//define value type return values6 if(string. IsNullOrEmpty (first))7 {8 return-1;9 }Ten if(string. IsNullOrEmpty (second)) One { A return-1; - } - //Split String the string[] Firstarray = first. Split ('-'); - string[] Secondarray = second. Split ('-'); -list<int> Intarray =Newlist<int>(); - //Record comparison results + for(inti =0; i < firstarray.length; i++) - { + BOOLFirstisnumber =int. TryParse (Firstarray[i], outfirstnumber); A BOOLSecondisnumber =int. TryParse (Secondarray[i], outsecondnumber); at if(Firstisnumber &&secondisnumber) - { - //Number Comparison - Intarray.add (Firstnumber.compareto (Secondnumber)); - } - Else { in //Text comparison - Intarray.add (Firstarray[i]. CompareTo (Secondarray[i])); to } + } -Intarray.reverse ();//Calculate the difference from the bottom of the number the intval =0; * //Get the difference ratio $ for(inti =0; i < Intarray.count; i++)Panax Notoginseng { -Val + = intarray[i] * (i+1) *Ten; the } + returnVal; A } the}
:
LINQ sorting based on text a-001-002-003 this type to split sort the null value is placed in the last