如何基于CurrentUICulture设置LINQ排序
var actorQuery = (from actor in actorList
where !actor.IsLocked
select new { Id = actor.Id, Name = string.Format("{0} {1}", actor.Name, actor.BusinessId) }).OrderBy(actor => actor.Name);
答案 0 :(得分:0)
订单由CurrentCulture
而非CurrentUICulture
确定
示例:
var a = new string[] {"å","ä","ö","a","b","c"};
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
a.OrderBy(x => x).Dump(); //a,b,c,å,ä,ö
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
a.OrderBy(x => x).Dump(); //a,ä,å,b,c,ö
因此,只需在设置CurrentCulture
的同时设置CurrentUICulture