gpt4 book ai didi

c# - 如何针对 ListCollectionView 编写 linq 查询?

转载 作者:可可西里 更新时间:2023-11-01 08:31:40 26 4
gpt4 key购买 nike

这些似乎都不起作用:

var source = myViewModel.MyListCollectionView.Select(x => x as MyType);
var source = myViewModel.MyListCollectionView.Select<object, MyType>(x => x as MyType);
var source = myViewModel.MyListCollectionView.SourceCollection.Select<object, MyType>(x => x as MyType);

最佳答案

ListCollectionView 仅实现非泛型 IEnumerable 接口(interface)。我怀疑你想要:

var source = myViewModel.MyListCollectionView.Cast<MyType>();

或者(如果某些值不是MyType,那没关系):

var source = myViewModel.MyListCollectionView.OfType<MyType>();

关于c# - 如何针对 ListCollectionView 编写 linq 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6142596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com