Linq Group 使用 Func加入?

发布于 2024-09-27 06:37:11 字数 230 浏览 3 评论 0原文

我有 IEnumerableIEnumerable 我想根据 A.Test(B) 是否返回 true 进行分组加入。

键选择器函数似乎没有这样做,因为 KeySelector 需要返回相同类型的键,以便可以检查它们是否相等。

我在这里缺少什么吗?

I have
IEnumerable<A> and IEnumerable<B>
I want to Group Join based on whether A.Test(B) returns true.

The keyselector funcs do not seem to do this as the KeySelectors need to return keys of the same type so that they can be checked for equality.

Is there something I'm missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀中猫帐中妖 2024-10-04 06:37:11

你是对的,GroupJoin 无法真正处理这种情况。
这个解决方法可以吗?

var res = from aInstance in aSequence 
          select new {
                       A = aInstance,
                       MatchingBs = bSequence.Where(bInstance => aInstance.Test(bInstance))
                     };

You're right, GroupJoin can't really handle this case.
Will this workaround do?

var res = from aInstance in aSequence 
          select new {
                       A = aInstance,
                       MatchingBs = bSequence.Where(bInstance => aInstance.Test(bInstance))
                     };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文