在< iEnumerable上进行过滤< igrouping>>返回无效CastException
我有一个私有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论