如何在C#中调用main函数? [英] How do I call the main function in C#?
问题描述
您好,
在以下代码中,我收到以下错误;
1.错误CS0234名称空间'PdfSloutions'中不存在类型或命名空间名称'Form1'(您是否缺少程序集引用?)
2. System.ArgumentNullException:'属性MainForm不能设置为Nothing。
参数名称:MainForm'
请帮忙。
我的尝试:
使用系统;
使用System.Collections;
使用System.Collections.Generic;
使用System.Data;使用System.Drawing
;
使用System.Diagnostics;
使用System.Windows.Forms;
使用System.Linq;
使用System.Xml.Linq;
namespace PdfSloutions
{
namespace My
{
内部分部类MyApplication:Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
{
[global :: System.Diagnostics.DebuggerStepThroughAttribute()]
public MyApplication():base(Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
{
this.IsSingleInstance = false;
this.EnableVisualStyles = true;
this.SaveMySettingsOnExit = true;
this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
}
[global :: System.Diagnostics.DebuggerStepThroughAttribute()]
protected override void OnCreateMainForm()
{
this.MainForm = global: :PdfSloutions.Form1.DefaultInstance;
}
private static MyApplication MyApp;
内部静态MyApplication应用程序
{
获取
{
返回MyApp;
}
}
[STAThread]
static void Main(string [] args)
{
System.Windows.Forms.Application .SetCompatibleTextRenderingDefault(假);
MyApp = new MyApplication();
MyApp.Run(args);
}
}
}
}
< blockquote>您没有显式调用Main方法。这是你的应用程序框架将调用的默认入口点。
你提到的错误告诉我没有任何名为 PdfSloutions.Form1
。在该命名空间中没有任何名为Form1的内容,如果是,则不公开。
Quote:如何在C#中调用main函数?
简答:你没有,从不。
'main'是一个特殊功能,它是程序的起点,你不能在你的代码中调用它。
Hello,
In the following code, I am getting the following errors;
1. Error CS0234 The type or namespace name 'Form1' does not exist in the namespace 'PdfSloutions' (are you missing an assembly reference?)
2. System.ArgumentNullException: 'Property MainForm cannot be set to Nothing.
Parameter name: MainForm'
Please help.
What I have tried:
using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Diagnostics; using System.Windows.Forms; using System.Linq; using System.Xml.Linq; namespace PdfSloutions { namespace My { internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase { [global::System.Diagnostics.DebuggerStepThroughAttribute()] public MyApplication() : base(Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows) { this.IsSingleInstance = false; this.EnableVisualStyles = true; this.SaveMySettingsOnExit = true; this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses; } [global::System.Diagnostics.DebuggerStepThroughAttribute()] protected override void OnCreateMainForm() { this.MainForm = global::PdfSloutions.Form1.DefaultInstance; } private static MyApplication MyApp; internal static MyApplication Application { get { return MyApp; } } [STAThread] static void Main(string[] args) { System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); MyApp = new MyApplication(); MyApp.Run(args); } } } }
You do not explicitly call Main method. That is the default entry point for your application which framework will call.
The errors you have mentioned tell that there nothing calledPdfSloutions.Form1
. Either there is nothing called Form1 in that namespace or if it is, it not public.
Quote:How do I call the main function in C#?
Short answer: You don't, never.
'main' is a special function, it is the starting point of your program and you can't call it in your code.
这篇关于如何在C#中调用main函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!