The problem I am trying to solve is to add multiple target frameworks (NET45 before and NETSTANDARD2.0 new) for a common library. The library contains a lot of utility classes to sort strings. I want to find the best way to keep .NET 5.0 applications to have the same sorting results as before. I want to find out what is the best way to proceed.
Here is an example.
Comparing .
and -
will return a different order in .NET Frameworks 4 and .NET 5. This is a breaking change.
The results in the two runtimes are:
.NET Frameworks 4.7: -1, which means
.
<_
- https://dotnetfiddle.net/I0yIr6.NET 5.0: 1 which means
.
>_
- https://dotnetfiddle.net/6YQCmA
using System;
using System.Globalization;
public class Program
{
public static void Main()
{
// returns -1 in NET47 but returns 1 in NET5_0
Console.WriteLine(string.Compare(".", "_", StringComparison.InvariantCulture));
Console.WriteLine(string.Compare(".", "_", StringComparison.CurrentCulture));
var cultureInfo = new CultureInfo("en-US", false);
Console.WriteLine(string.Compare(".", "_", true, cultureInfo));
}
}