Thread overview |
---|
January 22, 2016 why the sort result is different with C# | ||||
---|---|---|---|---|
| ||||
D code: auto arr = ["b1=1", "b=2","a1=1", "a=2"]; writeln(arr.sort()); output:["a1=1", "a=2", "b1=1", "b=2"] C# code: var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" }; Array.Sort(arr); output:["a=2","a1=1","b=2","b1=1"] |
January 22, 2016 Re: why the sort result is different with C# | ||||
---|---|---|---|---|
| ||||
Posted in reply to mzfhhhh | On Friday, 22 January 2016 at 06:53:29 UTC, mzfhhhh wrote:
> D code:
> auto arr = ["b1=1", "b=2","a1=1", "a=2"];
> writeln(arr.sort());
>
> output:["a1=1", "a=2", "b1=1", "b=2"]
>
> C# code:
> var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" };
> Array.Sort(arr);
>
> output:["a=2","a1=1","b=2","b1=1"]
I don't what string sorting criteria is using C#, but '9' < '=', so should be ["a1=1", "a=2", "b1=1", "b=2"]
|
January 22, 2016 Re: why the sort result is different with C# | ||||
---|---|---|---|---|
| ||||
Posted in reply to mzfhhhh | On Friday, 22 January 2016 at 06:53:29 UTC, mzfhhhh wrote:
> D code:
> auto arr = ["b1=1", "b=2","a1=1", "a=2"];
> writeln(arr.sort());
>
> output:["a1=1", "a=2", "b1=1", "b=2"]
>
> C# code:
> var arr = new string[]{ "b1=1", "b=2", "a1=1", "a=2" };
> Array.Sort(arr);
>
> output:["a=2","a1=1","b=2","b1=1"]
auto arr1 = ["b1=1", "b=2", "a1=1", "a=2"];
auto arr2 = ["b1 = 1", "b = 2", "a1 = 1", "a = 2"];
arr1.sort.writeln; // ["a1=1", "a=2", "b1=1", "b=2"]
arr2.sort.writeln; // ["a = 2", "a1 = 1", "b = 2", "b1 = 1"]
|
January 22, 2016 Re: why the sort result is different with C# | ||||
---|---|---|---|---|
| ||||
Posted in reply to mzfhhhh | i know the reason,C# have several compares methods. String.Compare , String.CompareOrdinal //now the output is same as the D code Array.Sort(arr, string.CompareOrdinal); |
Copyright © 1999-2021 by the D Language Foundation