我有一个源自库(萨摩)的自定义类,如下所示:
public class DCBaseNode : Node { public bool selected = false; }
和库中的Neighbors方法返回List< Node>.我希望能够这样做:
graph.Neighbors(theNode).Any(n => n.selected == true);
但Any认为n是节点,而不是DCBaseNode,所以它不理解.selected.
所以我尝试过:
graph.Neighbors(theNode).Any<DCBaseNode>(n => n.selected == true);
…这给了我这个错误:
Error CS1928: Type
System.Collections.Generic.List<Satsuma.Node>' does not contain a member
Any’ and the best extension method overload `System.Linq.Enumerable.Any(this System.Collections.Generic.IEnumerable,System.Func)’ has some invalid arguments
……但我不清楚论证是如何无效的.
解决方法
听起来你需要垂头丧气……
graph.Neighbors(theNode) .OfType<DCBaseNode>() .Any(n => n.selected);