订单列表与另一个列表的顺序相同
我有一个名为 AList 的 MyFirstObject 列表。 MyFirstObject 类有两个属性:ID、Name
我有另一个名为 BList 的 MySecondObject 列表。 MySecondObject 只有一个属性:ID
AList 按其 ID 属性排序。 BList 是随机排序的,而不是按其 ID 属性排序。我们想要实现BList在AList中的顺序。
(对拼写错误表示歉意)
例如
AList = [object ID = 1, object ID = 4, object ID = 5]
BList = [object ID = 4, object ID = 1, object ID = 5]
AList和BList中的元素数量相等。
我想确保 AList 中的所有项目的排序顺序与 BList 中的排序顺序相同。
你能建议一个方法吗?
问候
I have a list of MyFirstObject called AList. MyFirstObject class has two properties: ID, Name
I have another list of MySecondObject called BList. MySecondObject only has a property:ID
AList is ordered by its ID property. BList is randomly ordered and not by its ID property. We want to achieve the order of BList in AList.
(Apologies for the typo)
E.g.
AList = [object ID = 1, object ID = 4, object ID = 5]
BList = [object ID = 4, object ID = 1, object ID = 5]
The number of elements in AList and BList are equal.
I want to ensure that all of the items in AList are ordered in same order as they are ordered in BList.
Can you please suggest a way?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Linq 对 Id 上的两个列表进行排序:
这是您要寻找的吗?
Sorting both list on Id using Linq:
Is this what you where looking for?