相关疑难解决方法(0)

c#:控制台应用程序 - 静态方法

为什么在C#,控制台应用程序中,在"程序"类中,默认情况下,所有方法都必须是静态的

static void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)

c# static

44
推荐指数
4
解决办法
7万
查看次数

实例化包含static void Main()的类

我正在审查一个同事的C#控制台应用程序,我看到这个片段:

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

    ... non-static RealMain function
}
Run Code Online (Sandbox Code Playgroud)

据推测,他这样做是因为他想拥有实例级别的字段等.

我以前没见过这个,但这种风格让我感到困惑.这是一种常见且被接受的做法吗?

c# static program-entry-point instance console-application

6
推荐指数
2
解决办法
2833
查看次数