[英]Type casting from IEnumerable to ObservableCollection in C#
I want to get all the places which are active for bid. 我想得到所有正在竞标的地方。 I tries this but I'm getting null. 我尝试了这个,但是我变得空了。
testObservableList = testObservableList.Where(
x => x.IsActiveForBid) as ObservableCollection<Places>;
try this. 尝试这个。
testObservableList =
new ObservableCollection(testObservableList.Where(x => x.IsActiveForBid));
This will make a shallow copy of the current IEnumerable and turn it in to a ObservableCollection 这将创建当前IEnumerable的浅表副本,并将其放入ObservableCollection中。
While an ObservableCollection<T>
is IEnumerable<T>
the opposite does not hold. 当ObservableCollection<T>
是IEnumerable<T>
则相反。 Try a constructor: 尝试构造函数:
new ObservableCollection<SometypeType>(
testObservableList.Where(x => x.IsActiveForBid))
Try this: 尝试这个:
ObservableCollection coll1 = new ObservableCollection(testObservableList.Where(x => x.IsActiveForBid);
I guess this will do it. 我想这会做到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.