这是我有对象
[{State: "TX",
Type: {"Secondary", "Third"}},
{State: "PA",
Type: {"Primary","Secondary"}}
{State: "NC",
Type: {"Third", "Fourth","Fifth"}},
{State: "NJ",
Type: {"Primary", "Third"}}]
我要做的是命令/显示,以便第一个记录总是哪个有主要,后面是次要,第三个,第四个等。上面数据的结果应该是。 Primary,Secondary,Third等是枚举字符串,并且是硬编码的。关于如何在LINQ中实现这一点的任何指针。
[{State: "PA",
Type: {"Primary","Secondary"}},
{State: "NJ",
Type: {"Primary", "Third"}}]
{State: "TX",
Type: {"Secondary", "Third"}},
{State: "NC",
Type: {"Third", "Fourth","Fifth"}}]
答案 0 :(得分:1)
您需要使自定义类型实现接口IComparer。在这样做的同时,您将实现自己的比较逻辑。完成此操作后,您只需要在您的集合上调用order by,最后将根据您在IComparer实现中提供的自定义逻辑进行排序