Func- 等号是什么意思?
丹尼最初问这个问题是为了回应斯科特·汉塞尔曼最近的帖子:
谁能告诉我这是什么: Func<客户,bool="">可选的 参数有默认值吗?一个空的 布尔值的字符串?我将其替换为 函数,并得到 我的机器上有不同的结果! 一切顺利,我明白“在哪里” 不使用表达式的语句!
我知道我也见过这种 Func 疯狂,但我似乎无法得到 Func<> 。或表达式
出于好奇,Func 中的等号意味着什么(如果有的话),并且该功能在 C# 4.0 中是否已弃用?
[这个问题来自Scott Hanselman的博客:“每周源代码 52 - 你继续使用那个 LINQ,我不知道它的意思是什么。”]
Danny initially asked this question in response to a recent Scott Hanselman post:
Who can tell me what's this :
Func<Customer, bool=""> A optional
parameter with default value? A empty
string for a bool? I replace it with
Func, and get the
different result in my machine!
Everything works well, I get "where"
statement without using Expression!
I know I've seen this Func madness, too, but I can't seem to get a Func<> or an Expression<Func<>> of this type to compile in C# 4.0.
Out of curiosity, what does the equals sign in the Func mean, if anything, and has that functionality been deprecated in C# 4.0?
[This question comes from Scott Hanselman’s blog: “The Weekly Source Code 52 - You keep using that LINQ, I dunna think it means what you think it means.”]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你说你见过它......我怀疑你在编译的代码中见过它。
如果有,请举个例子:因为在我以这种方式看到真实代码之前,我 99% 确定它不是有效的 C#。
You say you've seen it... I doubt that you've seen it in code which compiles.
If you have, please give an example: because until I see real code that way, I'm 99% sure it's just not valid C#.
根据 Visual C# 4.0 语言规范、ISO C# 语言规范(它是 Visual C# 2.0 的子集)、Visual Studio 2010 语法荧光笔和 Visual C# 4.0 编译器,这不是合法的 C# 代码。它甚至在语法上都不合法,即它甚至无法解析,更不用说在语义上合法了。
因此,它根本没有任何意义。
According to the Visual C# 4.0 Language Specification, the ISO C# Language Specification (which is a subset of Visual C# 2.0), the Visual Studio 2010 Syntax Highlighter and the Visual C# 4.0 Compiler, this is not legal C# code. It isn't even syntactically legal, i.e. it doesn't even parse, let alone semantically legal.
Therefore, it simply doesn't mean anything.
我认为您需要阅读 斯科特的回答 评论里,他的博客软件被玩起来了。
这里没什么可看的!!
I think you need to read Scott's answer in the comments, his blog software was playing up.
Nothing to see here!!
(1) http://bitbucket.org/alexg/syntaxhighlighter/issue/154/c-brush-lacks-c-3-and-4-keywords
Bug #154 C# 画笔缺少 C# 3、4个关键词
- group、orderby、from、var、select、ascending、descending、into、join、let、dynamic、add、remove、where(导致一些 LINQ 语法问题)
(2) hxxp://bitbucket.org/alexg/syntaxhighlighter /issue/165/using-in-code-产生
Bug #165 使用 <和>在代码中产生 <和“”>
注意:小心使用:
(3) 是的 Alex (SyntaxHighlighter) 知道它:
hxxp://alexgorbatchev.com /forums/comments.php?DiscussionID=200&page=1#Item_0
论坛主题:LINQ 无法在 C# 中工作
(1) http://bitbucket.org/alexg/syntaxhighlighter/issue/154/c-brush-lacks-c-3-and-4-keywords
Bug #154 C# brush lacks C#3 and 4 keywords
- group, orderby, from, var, select, ascending, descending, into, join, let, dynamic, add, remove, where (resulting in some LINQ syntax issues)
(2) hxxp://bitbucket.org/alexg/syntaxhighlighter/issue/165/using-in-code-produces
Bug #165 Using < and > in code produces < and ="">
Note: Be careful to use:
<script type="syntaxhighlighter" class="brush: csharp">
(3) Yes Alex (SyntaxHighlighter) knows about it:
hxxp://alexgorbatchev.com/forums/comments.php?DiscussionID=200&page=1#Item_0
Forum thread: LINQ not working in C#
我怀疑它是否有效。
即使
Func
支持最佳参数,最后一个类型参数也是结果。I doubt it's valid.
Even if
Func
supported optimal arguments, the last type argument is the result.