本文介绍了关于构造函数和主要方法执行的一点困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我们有一个构造函数和main()方法,首先会在执行表单/页面时调用它?
if we have a "constructor" and the "main()" method whichone will called first on the execution of the form/page?
推荐答案
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//new Form1 CONSTRUCTS the form.
Application.Run(new Form1());
}
}
使用<$ c从类生成对象时调用构造函数$ c> new keyword。
这是从模板=类构造对象的方法。这是通过实例化变量,事件,方法来完成的。
希望这会有所帮助。
The Constructor is called when you generate an object from a class with the new
keyword.
It is the method that "constructs" the "object" from a template = the "class". This is done by instantiating the variables, event, methods, ...
Hope this helps.
这篇关于关于构造函数和主要方法执行的一点困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!