C#: Function in Function possible?

前端 未结 7 976
面向向阳花
面向向阳花 2020-12-05 05:59

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

For example like that:

void OuterMethod()
{
    int anything = 1;
    InnerMethod();          


        
7条回答
  •  情歌与酒
    2020-12-05 06:51

    If you're looking mainly to "hide" a method that is just a "helper" ... another option is to make your helper(s) private. That way they don't become part of your class's public interface.

    This has the advantage that the helper(s) can be reused if necessary; but it / they won't be "internal" to the calling method.

提交回复
热议问题