我正在尝试转换并订购一组字符串。
模特:
public class PartnerSearchResultDTO
{
public int Id { get; set; }
public string Distance { get; set; }
public int Classification { get; set; }
}
我在哪里有一套:
IList<PartnerSearchResultDTO> partnersDTO = new List<PartnerSearchResultDTO>();
partnersDTO =
Id = 1 | Distance = "2,7" | Classification = 1
Id = 2 | Distance = "5" | Classification = 1
Id = 3 | Distance = "4,3" | Classification = 1
Id = 4 | Distance = "5,2" | Classification = 1
Id = 5 | Distance = "8" | Classification = 1
我这样订购:
partnersDTO = partnersDTO.ToList().OrderBy(p => double.Parse(p.Distance)).ToList();
如果浏览器的语言设置为Portugues“pt-PT”,则它会正确排序:
2,7 -> 4,3 -> 5 -> 5,2 -> 8
如果浏览器的语言设置为英语“en-us”,它会忽略逗号和命令,如下所示:
5 -> 8 -> 2,7 -> 4,3 -> 5,2