net472 vs net6.0: Default string sorting

77 Views Asked by At

I have this mini program:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net472;net6.0</TargetFrameworks>
  </PropertyGroup>
</Project>

using System;
using System.Collections.Generic;
using System.Linq;

internal static class Program
{
    private static void Main()
    {
        var list = new List<string>()
        {
            "were",
            "we're",
            "weird",
        };

        foreach (var item in list.OrderBy(i => i))
        {
            Console.WriteLine(item);
        }
    }
}

When compiled as net472 I get

weird
were
we're

When I compile as net6.0 I get

we're
weird
were

Is there a way to configure or determine what kind of sorting rule is applied by default?

Edit:

It is indeed, as Alexander Petrov said, the difference between ICU and NLS

Configuring the project file as such makes them both behave identically:

<ItemGroup>
  <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>
0

There are 0 best solutions below