Using MethodInfo.GetCurrentMethod() in anonymous methods

前端 未结 3 1633
日久生厌
日久生厌 2021-01-18 02:38
public static void Main(string[] args)
{
    Action a = () => Console.WriteLine(MethodInfo.GetCurrentMethod().Name);
    a();
}

This code will r

3条回答
  •  醉酒成梦
    2021-01-18 02:43

    You could capture it outside:

    var name = MethodInfo.GetCurrentMethod().Name + ":subname";
    Action a = () => Console.WriteLine(name);
    

    Other than that; no.

提交回复
热议问题