问题标签 [anonymous-methods]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 如何在 C# 中返回通用列表集合?
我有一些 linq to sql 方法,当它执行查询时,它返回一些匿名类型。
我想将该匿名类型返回到我的服务层以对其进行一些逻辑和处理。
虽然不知道怎么退货。
我以为我能做到
但我得到这个错误
所以不确定我缺少什么程序集,或者是否是这种情况。
谢谢
编辑
好的,我的第一个问题已经解决,但现在我有一个新问题,我不知道如何解决,因为我对匿名类型了解不多。
我收到这个错误
无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List”
这是查询
编辑 2
选择里面有这个
c# - 匿名方法和异步 I/O
如果我对异步 I/O 使用匿名方法,谁能告诉我是否可能会遇到意外行为?
举个例子:
这同样适用于 BeginXXX/EndXXX 异步 I/O。
c# - 为什么匿名委托/lambdas 不推断 out/ref 参数的类型?
StackOverflow 上的几个 C# 问题询问如何使用out
或ref
参数制作匿名委托/lambda。参见,例如:
为此,您只需指定参数的类型,如下所示:
我很好奇的是为什么明确需要该类型。有什么特别的原因会出现这种情况吗?也就是说,从编译器/语言的角度来看,为什么不允许以下内容?
甚至更好,只是:
c# - Replacing a regular method with an anonymous method in C#/LINQ
I have a LINQ query that looks like this:
I would like to get rid of AddMissingProp
and use some form of a lambda in my select
clause instead.
I attempted...
...but I got the following error:
A local variable named 'f' cannot be declared in this scope because it would give a different meaning to 'f', which is already used in a 'parent or current' scope to denote something else.
How can I "lambda-ize" my query?
Update
This also doesn't work:
I get the following error:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
I didn't change the join
clause at all, so I'm perplexed.
c# - 不能在成员初始化程序中使用“this”?
这合法吗?它是否包含隐藏的错误或缺陷?Visual Studio 不会给出任何错误或警告,但 ReSharper 会:
c# - 添加和删除匿名事件处理程序
我想知道这是否真的有效?
编译器如何知道事件处理程序是相同的?这甚至被推荐吗?
c# - 具有匿名方法的BackgroundWorker?
我将使用匿名方法创建一个BackgroundWorker 。
我写了以下代码:
但是委托'System.ComponentModel.DoWorkEventHandler'不接受'0'参数,我必须将两个对象传递给匿名方法:对象发送者,DoWorkEventArgs e
你能指导我吗,我该怎么做?谢谢。
c# - C# 事件处理程序委托中的闭包?
我目前来自函数式编程背景,如果我不了解 C# 中的闭包,请原谅我。
我有以下代码来动态生成获取匿名事件处理程序的按钮:
我希望文本在 for 循环的该迭代中"I am button number " + i
以 的值关闭。i
但是,当我实际运行程序时,每个 Button 都会显示I am button number 7
. 我错过了什么?我正在使用VS2005。
编辑:所以我想我的下一个问题是,我如何捕捉价值?
delphi - 接口、匿名方法和内存泄漏
这是一个构建的例子。我不想在这里发布原始代码。我试图提取相关部分。
我有一个管理听众列表的界面。
现在我注册一个监听器:
我确实有内存泄漏。匿名方法和接口都永远不会被释放。我怀疑这是由于这里的某种循环引用。匿名方法使接口保持活力,接口使匿名方法保持活力。
两个问题:
- 你支持这个解释吗?还是我在这里错过了其他东西?
- 我能做些什么吗?
提前致谢!
编辑:在一个小到可以在此处发布的应用程序中重现它并不容易。我现在能做的最好的事情如下。匿名方法不会在这里发布:
delphi - 在 Delphi 2009 中铸造匿名程序
以下代码(仅用于演示问题)在 Delphi 2010 中编译和工作。在 Delphi 2009 中,编译器失败并显示“E2035 Not enough actual parameters”。
我发现只有一个非常丑陋的黑客可以解决这个问题(a:TProc absolute b)。有没有人知道这个编译器缺陷的更好的解决方法?
[TProc 字段实际上隐藏在可以存储各种“可执行”代码的记录中 - TProcedure、TMethod 和 TProc。Casting 用于将特定的匿名 proc 存储到此字段中。]