我看到有人在Func <>模式下面写下类型。我正在尝试与Funcs和Lambdas合作,让概念正确。C#Func <>和扩展方法问题
so ExperimentalSelect返回一个Func(带有2个参数和bool返回值)。
但我不明白所有3个返回语句是如何有效的(每次1个)。
public static Func<BinaryTreeNode<int>, int, bool> nodeSelector = (x, y) =>
{
return x.Value > y;
};
public static Func<int, int, bool> intSelector = (x, y) =>
{
return x > y;
};
public static Func<BinaryTreeNode<int>, int, bool> ExperimentalSelect (int number)
{
return nodeSelector; // seems straightforward, i agree this should work
// how does this work ? intSelector is different type Func<>
// and it is executing it here, thereby returning the bool type result
// and not Func<> type as the return type of this method should
return (x, y) => intSelector(number, number);
// and how does this work ? what is node here ?
// and SomeMethod returns bool and not Func<> type
return (node, x) => SomeMethod(node, number, true);
}
private static bool SomeMethod(BinaryTreeNode<int> node, int someNumber,
bool doSomething)
{
return node.Value < someNumber;
}
编辑:
如果一个分机。方法需要一个FUNC
IEnumerable<int> selected = tree.TakeWhile(ExperimentalSelect);
如何在这里工作的someMethod?,它不是一个Func键<>!
是什么意思语法:
(node, x) => SomeMethod(node, number, true);
哪里是在图片浏览的节点或x?
请参阅我的答案更新。也许这会让事情变得更清晰。 – 2011-05-31 11:52:02
@丹尼尔。我看到了。说得通。你能看到我对你答案的评论吗? – 2011-05-31 11:54:20