本文介绍了为什么在大多数C#程序的主要方法入口点静态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在大多数C#程序静态的?
Why is the main method entry point in most C# programs static?
推荐答案
的主要方法入口点为了调用你需要一个实例方法一个对象的一个实例。这意味着为了启动程序的CLR将需要以调用方法来创建发言权程序
的实例主
。因此,程序的构造
将主
这违背了完全具有主的目的之前运行。
In order to call an instance method you need an instance of an object. This means in order to start your program the CLR would need to create an instance of say Program
in order to call the method Main
. Hence the constructor of Program
would run before Main
which defeats the purpose of having a main altogether.
这篇关于为什么在大多数C#程序的主要方法入口点静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!