在< iEnumerable上进行过滤< igrouping>>返回无效CastException

发布于 2025-01-30 06:50:49 字数 597 浏览 1 评论 0原文

我有一个私有iEnumerable< igrouping< string myclass>> myGrouping;

我正在这样做:

foreach (IGrouping<string, MyClass> filteredGrouping in myGrouping.Select(x => x.TakeWhile(t => t.MyProperty != 0))) {

    string n = filteredGrouping.Key;

    // do things
}

因为我想在foreach中运行代码,仅当myproperty具有值时。

但是我的代码导致以下例外:

'无法施放类型'd_217'的对象[myproject.myfolder.myclass]'type'system.linq.grouping`2 [ssystem.string,myproject.myfolder.myclass]'。'

>

我的方法有什么问题,如何纠正它?

I have a private IEnumerable<IGrouping<string MyClass>> myGrouping;

And I am doing this with it:

foreach (IGrouping<string, MyClass> filteredGrouping in myGrouping.Select(x => x.TakeWhile(t => t.MyProperty != 0))) {

    string n = filteredGrouping.Key;

    // do things
}

Because I want to run the code in foreach only when MyProperty has value.

But my code causes the following exception:

'Unable to cast object of type 'd_217'[MyProject.MyFolder.MyClass]' to type 'System.Linq.IGrouping`2[Ssystem.String,MyProject.MyFolder.MyClass]'.'

What is wrong with my approach and how can I rectify it?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文