gpt4 book ai didi

c# - 是否可以使 IEnumerable 实现 IComparable?

转载 作者:行者123 更新时间:2023-11-30 22:29:27 26 4
gpt4 key购买 nike

如题。

我们都知道如果我们希望一个类具有可比性并用于排序,即 DataGrid,我们将实现 IComparable。

但是对于 IEnumerable 我该怎么做呢?

我有一个 IEnumerable 的集合,我们想将每个 IEnumerable 相互比较并进行排序。

这么说一个集合List<IEnumerable<char>>其中包含:

IEnumerable<char> EnumableA包含:“d”、“e”、“f”

IEnumerable<char> EnumableB包含:“d”、“e”、“c”

如果我们绑定(bind)集合 List<IEnumerable<char>>到数据网格,当我们按 acs 顺序对它们进行排序时,顺序将为 EnumableB第一,然后 EnumableA第二个。

我确实想到了存储 EnumableA 等解决方案进入实现的对象 IComparable ,但这将需要创建另一个对象集合,这将是昂贵的。

那么有没有可能或者无论如何附加一个IComparable界面和我对 IEnuerable<char> 的排序实现所以它将是可排序的?

最佳答案

看看这个帖子: Use own IComparer<T> with Linq OrderBy

使用 linq.orderby 传入您的 IComparable。

关于c# - 是否可以使 IEnumerable<char> 实现 IComparable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10220253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com