c# : console application - static methods

前端 未结 5 718
[愿得一人]
[愿得一人] 2020-12-24 01:26

why in C#, console application, in \"program\" class , which is default, all methods have to be static along with

static void Main(string[] args)

5条回答
  •  感动是毒
    2020-12-24 01:36

    You can write non static methods too, just you should use like this

    static void Main(string[] args)
    {
        Program p = new Program();
        p.NonStaticMethod();
    }
    

    The only requirement for C# application is that the executable assembly should have one static main method in any class in the assembly!

提交回复
热议问题