C#:功能的功能可能吗?功能

由网友(佛说要宠我)分享简介:是否有可能在C#声明中的另一个方法的方法?例如这样的:无效OuterMethod(){INT任何= 1;InnedMethod();无效InnerMethod(){INT PlitschPlatsch = 2;}}解决方案 不能直接否定的。 C#不支持内部的方法。它不支持匿名方法虽然可以达到同样的目的。无效Oute...

是否有可能在C#声明中的另一个方法的方法?

例如这样的:

 无效OuterMethod()
{
    INT任何= 1;
    InnedMethod();
    无效InnerMethod()
    {
        INT PlitschPlatsch = 2;
    }
}
 

解决方案

不能直接否定的。 C#不支持内部的方法。它不支持匿名方法虽然可以达到同样的目的。

 无效OuterMethod()
{
    INT任何= 1;
    行动InnedMethod =()=>
    {
        INT PlitschPlatsch = 2;
    };
    InnedMethod();
}
 
c jave等语言作用,编程语言的前世今生,看 Java C C 等语言的演变

Is it possible to declare a method within another method in C#?

For example like that:

void OuterMethod()
{
    int anything = 1;
    InnedMethod();
    void InnerMethod()
    {
        int PlitschPlatsch = 2;
    }
}

解决方案

Not directly no. C# doesn't support inner methods. It does support anonymous methods though which can serve the same purpose

void OuterMethod()
{
    int anything = 1;
    Action InnedMethod = () =>
    {
        int PlitschPlatsch = 2;
    };
    InnedMethod();
}

阅读全文

相关推荐

最新文章