我有一台Windows 2019服务器(所有语言设置都设置为en-US),其代码如下:
var unsorted = new[] {"Aldi", "Al-Murad Tiles", "AliExpress" };
Console.WriteLine("Unsorted: " + string.Join(',', unsorted));
var sorted = unsorted.OrderBy(x => x);
Console.WriteLine("Sorted: " + string.Join(',', sorted));
生产:
我有一台Windows 11机器(所有语言设置都设置为en-GB),同样的代码会产生:
如果我将当前线程的区域性设置为与服务器相同,则没有区别:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
有人知道应该对当前线程应用什么设置,以使Windows 11计算机上的现有代码排序与服务器上的相同吗?
(worth saying this is an example extracted from a much larger legacy codebase so I'd like to make minimal code changes to the affect the current thread/context/environment to make this sorting work rather than re-factor the existing code)个