Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
您缺少一个分号,它会编译:
当您说
type name = statements;
时,即使您在代码块中使用大括号,您也需要一个分号。You are missing a semi-colon, it compiles:
When you say
type name = statement;
you need a semicolon even if you use braces for a code block.cfeduke 发布了编译代码的解决方案。
请注意,您无法将语句块 lambda 表达式转换为表达式树,即使您可以将它们转换为委托。 对于可以转换为表达式树的内容,还有其他限制。
回到委托,那里有一些限制 - 例如,您不能在 lambda 表达式中编写迭代器块。 (我以前就想这样做 - 当你试图解决这个问题时,它会变得很奇怪。尽管你做不到。)在大多数情况下,你几乎可以用一种方法做任何你能做的事情。
cfeduke has posted the solution to getting your code to compile.
Note that you can't convert statement-block lambda expressions into expression trees, even though you can convert them into delegates. There are other limitations on what you can convert into expression trees.
Going back to delegates, there are some limitations there - you can't write an iterator block within a lambda expression, for example. (I've wanted to do that before now - it gets weird when you try to get your head round it. You can't do it though.) For the most part, you can do almost anything you can do in a method.