我有一个名为A
的基类和两个子类B
和C
:
class B : A
{
public string Description { get; set; }
}
class C : A
{
public string AnotherProperty { get; set; }
}
我从一个方法中得到一个数组,该方法返回B
和C
的数组如果B.Description == "some text";
请帮助我如何做到这一点。
List<A> list = ....
var query = list.OfType<B>().Where(b => b.Description != "some text");
如果你还想要所有不是B
:
var query = list.Where(a => !(a is B) || ((B)a).Description != "some text"));