强制转换 IEnumerable到 ObservableCollection没有构造函数注入 IEnumerable
我怎样才能做到这一点?
这是不行的:
ObservableCollection obsCol = new ObservableCollection(myIEnumerable);
场景:
var query = from c in customers
select new Customer()
{
Products = from p in products
where p.Id = c.Id
select p
};
Products是一个ObservableCollection,所以它不能从上面的选择中获取IEnumerable结果...
如何转换?
How can I do that?
thats a no go:
ObservableCollection obsCol = new ObservableCollection(myIEnumerable);
scenario:
var query = from c in customers
select new Customer()
{
Products = from p in products
where p.Id = c.Id
select p
};
Products is a ObservableCollection so it can not take the IEnumerable result from the select above...
How to cast?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样:
请注意,
ObservableCollection
实例不会反映对customers
列表的更改。编辑:Select 扩展方法返回编译器生成的迭代器类的实例。由于此类不继承ObservableCollection,因此不可能将其转换为ObservableCollection。
Like this:
Note that the
ObservableCollection
instance will not reflect changes to thecustomers
list.EDIT: The Select extension method returns an instance of a compiler-generated iterator class. Since this class does not inherit
ObservableCollection
, it is impossible to cast it to one.