正如您在下面的代码中看到的,我已将Action<>对象声明为变量.
有人请让我知道为什么这个动作方法委托表现得像一个静态方法?
为什么它会true在以下代码中返回?
public static void Main(string[] args)
{
Action<string> actionMethod = s => { Console.WriteLine("My Name is " + s); };
Console.WriteLine(actionMethod.Method.IsStatic);
Console.Read();
}
Run Code Online (Sandbox Code Playgroud)

为什么 Roslyn 编译器生成带有internal访问修饰符(在 IL 中,assembly)而不是 的本地函数private?
private void M()
{
bool f = true;
bool x1() => f;
static bool x2() => true;
}
Run Code Online (Sandbox Code Playgroud)
.method assembly hidebysig static
bool '<M>g__x1|0_0' (
valuetype C/'<>c__DisplayClass0_0'& ''
) cil managed { ... }
.method assembly hidebysig static
bool '<M>g__x2|0_1' () cil managed { ... }
Run Code Online (Sandbox Code Playgroud)
文档说它应该是私有的: https: //learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions
本地函数是嵌套在另一个成员中的类型的私有方法。
由于所有本地函数都是私有的,包括访问修饰符(例如 private 关键字),会生成编译器错误 CS0106