小编Nel*_*usa的帖子

程序类应该是静态的吗?

创建新的ASP.NET Core 3项目后,在Visual Studio 2019中收到以下警告:

Warning CA1052 Type 'Program' is a static holder type but is neither static nor NotInheritable

public class Program
    {
        public static void Main(string[] args)
        {
            // ...
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            // ...
    }
Run Code Online (Sandbox Code Playgroud)

vs

public static class Program
    {
        public static void Main(string[] args)
        {
            // ...
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            // ...
    }
Run Code Online (Sandbox Code Playgroud)

Should I add the static modifier? Why / Why not? Pro's and Cons'?

Edit: …

c# asp.net asp.net-core

4
推荐指数
1
解决办法
175
查看次数

标签 统计

asp.net ×1

asp.net-core ×1

c# ×1