OrderBy with Swedish letters

旧城冷巷雨未停 提交于 2019-12-04 01:33:15
TheCodeKing

You can use culture specific StringComparer, see here.

CultureInfo culture = new CultureInfo("sv-SE");
var result = myList.OrderByDescending(x => 
               x.Title, StringComparer.Create(culture, false));

Set the Thread.CurrentCulture property to the correct culture.

I my case: _My sorting list have value was encoded. This make my order incorrect. Add decoded solving my problems !

The workaround I found for a somewhat similar problem was to have a secondary field that held the converted version of the data.
In my case, we had person.Name and person.SearchName, where SearchName was Name converted to have no diacritics.

But this was only the best approach (AFAIK) because we wanted a speedy db search/filtering and then instantiating only the relevant results.
If you already have the objects in memory I would advise going with one of the other approaches; and not this one.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!