Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:我可以';不明白_C# - Fatal编程技术网

C#:我可以';不明白

C#:我可以';不明白,c#,C#,我收到了三个错误,它们阻止了我的程序运行,我不明白它们是什么意思?我一定很愚蠢,因为我甚至把我的C#book放在旁边,但它仍然没有意义。任何帮助都会很好。错误是: Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe'定义了多个入口点:“WindowsFormsApplication1.Program.Main()”。使用/main编译以指定包含入口点的类型 “WindowsFormsAppl

我收到了三个错误,它们阻止了我的程序运行,我不明白它们是什么意思?我一定很愚蠢,因为我甚至把我的C#book放在旁边,但它仍然没有意义。任何帮助都会很好。错误是:

  • Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe'定义了多个入口点:“WindowsFormsApplication1.Program.Main()”。使用/main编译以指定包含入口点的类型

  • “WindowsFormsApplication1.Form1.Dispose(bool)”:未找到可重写的合适方法

  • Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe'定义了多个入口点:“Text.Main()”。使用/main编译以指定包含入口点的类型

  • 代码:

    program.cs代码为:

     namespace WindowsFormsApplication1
     {
     static class Program
     {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
     }
     }
    
    命名空间窗口窗体应用程序1
    {
    静态类程序
    {
    /// 
    ///应用程序的主要入口点。
    /// 
    [状态线程]
    静态void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(新Form1());
    }
    }
    }
    
    表格1的更新代码:

     namespace WindowsFormsApplication1
     {
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
    
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    
        #region Windows Form Designer generated code
    
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
    
        }
    
        #endregion
    }
    
    命名空间窗口窗体应用程序1
    {
    部分类Form1
    {
    /// 
    ///必需的设计器变量。
    /// 
    private System.ComponentModel.IContainer components=null;
    /// 
    ///清理所有正在使用的资源。
    /// 
    ///如果应释放托管资源,则为true;否则为false。
    #区域Windows窗体设计器生成的代码
    /// 
    ///设计器支持所需的方法-不修改
    ///此方法的内容与代码编辑器一起使用。
    /// 
    私有void InitializeComponent()
    {
    这个.SuspendLayout();
    // 
    //表格1
    // 
    此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
    this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize=新系统.Drawing.Size(284262);
    this.Name=“Form1”;
    this.Text=“Form1”;
    this.Load+=new System.EventHandler(this.Form1\u Load);
    此选项为.resume布局(false);
    }
    #端区
    }
    
    }

    Program.CS代码:

     using System;
     using System.Collections.Generic;
     using System.Linq;
     using System.Windows.Forms;
    
     namespace WindowsFormsApplication1
     {
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Text());
        }
    }
    
    使用系统;
    使用System.Collections.Generic;
    使用System.Linq;
    使用System.Windows.Forms;
    命名空间Windows窗体应用程序1
    {
    静态类程序
    {
    /// 
    ///应用程序的主要入口点。
    /// 
    [状态线程]
    静态void Main()
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    运行(新文本());
    }
    }
    

    }

    首先,如果您使用内置模板创建WinForms应用程序,则不需要在类
    Text
    中使用另一个
    Main
    方法,因为它已在
    Program.cs
    文件中定义

    我希望从类
    Text
    中删除冗余的
    Main
    方法可能足以成功运行应用程序


    编辑 在
    Program.cs
    文件中,实例化
    Text
    类,而不是
    Form1
    ,如下所示:

    namespace WindowsFormsApplication1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Text());
            }
        }
    }
    
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    

    编辑2: 请重写类
    Form1
    中的
    Dispose()
    方法,如下所示:

    namespace WindowsFormsApplication1
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Text());
            }
        }
    }
    
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    

    基于这些错误,您的项目中似乎还有一些其他代码-Form1.cs和Program.cs。你能把那些也寄出去吗?您可能可以删除这些方法或将其从项目中排除以解决错误。查看您的项目,您可能有一个
    Program.cs
    文件,该文件已经定义了主方法(您在上述代码末尾放置的方法)。您可以删除表单类中的主方法。现在我收到错误:“WindowsFormsApplication1.Form1.Dispose(bool)”:未找到可重写的合适方法否,您再次发布了类的代码
    Text
    。请将课程
    上传至Form1
    。非常感谢。你是救命恩人,没关系。我不配那样。我们全能的造物主是唯一的救星。顺便说一句,祝你好运!