📌  相关文章
📜  使用 C# 代码示例将方法作为参数传递

📅  最后修改于: 2022-03-11 14:48:40.797000             🧑  作者: Mango

代码示例1
public class Class1
{
    public int Method1(string input)
    {
        //... do something
        return 0;
    }

    public int Method2(string input)
    {
        //... do something different
        return 1;
    }

    public bool RunTheMethod(Func myMethodName)
    {
        //... do stuff
        int i = myMethodName("My String");
        //... do more stuff
        return true;
    }

    public bool Test()
    {
        return RunTheMethod(Method1);
    }
}