0

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>
Dee J. Doena
  • 1,631
  • 3
  • 16
  • 26
  • Are you running the two under the same locale settings? – KristoferA Aug 30 '23 at 16:16
  • @KristoferA compiled under Visual Studio at the same time in the same environment – Dee J. Doena Aug 30 '23 at 16:19
  • 2
    This is probably due to the differences between NLS and ICU. See [.NET globalization and ICU](https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu). – Alexander Petrov Aug 30 '23 at 16:49
  • 2
    When using `UseNls`, then in .NET6 gets the same result as in .NET4.7. – Alexander Petrov Aug 30 '23 at 17:06
  • 1
    @DeeJ.Doena keep in mind that .NET Core is cross-platform. If you use UseNls you'll end up with an unexpected sort when your code runs on Linux, eg if you deploy your web app using Docker or to a cloud provider – Panagiotis Kanavos Aug 30 '23 at 17:21
  • @PanagiotisKanavos thanks for the info and this wasn't really productive code just one of my tools for private use which I converted to net6 for educational purposes when I stumbled over this difference and tried to understand what's behind it. – Dee J. Doena Aug 30 '23 at 18:31

0 Answers0