why the sort result is different with C#

arturg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 22 00:46:15 PST 2016


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"]




More information about the Digitalmars-d-learn mailing list