为什么我在Visual Studio Basic中不包含静态主要错误?

问题描述 投票:-1回答:1

enter image description here

你们中的许多人以前可能都看过这个程序,如果这是一个非常初学者的问题,我们感到抱歉。我遇到错误cs5001程序不包含适用于入口点的静态“主”方法。我不确定要添加什么,请问有人可以协助我吗?

下面是我的代码,以及窗口表单的屏幕截图。谢谢您的时间!

namespace redactedHomework2
{

        public partial class Form1 : Form
        {
            const double CLASS_A_PRICE = 15;
            const double CLASS_B_PRICE = 12;
            const double CLASS_C_PRICE = 9;

        public Form1()
        {
            InitializeComponent();
        }
        private void Button1_Click(object sender, EventArgs e)
            {
                try
                {
                    double classA, classB, classC;
                    double classArev;
                    double classBrev;
                    double classCrev;
                    double total;

                    classA = double.Parse(textBox1.Text);
                    classB = double.Parse(textBox2.Text);
                    classC = double.Parse(textBox3.Text);

                    classArev = classA * CLASS_A_PRICE;
                    classBrev = classB * CLASS_B_PRICE;
                    classCrev = classC * CLASS_C_PRICE;
                    total = classArev + classBrev + classCrev;

                    textBox4.Text = classArev.ToString("c");
                    textBox5.Text = classBrev.ToString("c");
                    textBox6.Text = classCrev.ToString("c");
                    textBox7.Text = total.ToString("c");

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        private void Button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

}
c# visual-studio error-handling syntax compiler-errors
1个回答
1
投票

如果缺少Program.cs,请在解决方案资源管理器中向项目添加一个新类,并将其命名为“ Program.cs”。

右键单击项目名称>添加>类。

在其中输入以下代码:

using System;
using System.Windows.Forms;

namespace redactedHomework2 
{
  static class Program
  {
    [STAThread]
    static void Main()
    {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
    }
  }
}

检查项目属性是否为“ Windows应用程序”输出类型。

或者您可以尝试直接在您的Form1类中添加Main方法。

否则,您可以在另一个文件夹中启动新项目,然后导入Form1文件。

© www.soinside.com 2019 - 2024. All rights reserved.