gpt4 book ai didi

c# - C# 中的默认委托(delegate)

转载 作者:可可西里 更新时间:2023-11-01 08:33:45 30 4
gpt4 key购买 nike

C# 中不带参数并返回 void 的默认委托(delegate)的名称是什么?我记得有这样一个委托(delegate),但我不记得它的名字。

最佳答案

在 .NET 3.5 之前,声明您自己的内容相当普遍。现在,Action 是一个很好的候选者,但是 ThreadStart 是常用的(相当令人困惑),或者 MethodInvoker if 你已经在引用 winforms。

快速测试(注意,在 .NET 4.0 中运行,仅使用一些库 - 所以并不详尽):

var qry = from asm in AppDomain.CurrentDomain.GetAssemblies()
from type in asm.GetTypes()
where type.IsSubclassOf(typeof(Delegate))
let method = type.GetMethod("Invoke")
where method != null && method.ReturnType == typeof(void)
&& method.GetParameters().Length == 0
orderby type.AssemblyQualifiedName
select type.AssemblyQualifiedName;
foreach (var name in qry) Console.WriteLine(name);

显示更多候选人:

System.Action, mscorlib...
System.CrossAppDomainDelegate, mscorlib...
System.IO.Pipes.PipeStreamImpersonationWorker, System.Core...
System.Linq.Expressions.Compiler.LambdaCompiler+WriteBack, System.Core...
System.Net.UnlockConnectionDelegate, System...
System.Runtime.Remoting.Contexts.CrossContextDelegate, mscorlib...
System.Threading.ThreadStart, mscorlib...
System.Windows.Forms.AxHost+AboutBoxDelegate, System.Windows.Forms...
System.Windows.Forms.MethodInvoker, System.Windows.Forms...

关于c# - C# 中的默认委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4067061/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com