简体   繁体   English

Visual C#Beginner Empty Project帮助?

[英]Visual C# Beginner Empty Project Help?

I'm a beginner to Visual Studio, I can create Windows From Projects and Console Projects just fine, but I can't compile Empty Projects, 我是Visual Studio的初学者,我可以很好地从项目和控制台项目创建Windows,但我无法编译空项目,

The steps I take are: 我采取的步骤是:

  1. Create an Empty Project. 创建一个空项目。
  2. Add a class, add a reference to System and System.Windows.Forms 添加一个类,添加对System和System.Windows.Forms的引用
  3. Put the following code in the class: 将以下代码放在类中:

     using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace Circles { class Program { static void Main(string[] args) { MessageBox.Show("Hello World!"); } } } 

Then I hit compile, and it gives me this error: 然后我点击编译,它给了我这个错误:

Error 1 Program 'D:\\C #\\Projects\\Circles\\Circles\\obj\\x86\\Debug\\Circles.exe' does not contain a static 'Main' method suitable for an entry point Circles 错误1程序'D:\\ C#\\ Projects \\ Circles \\ Circles \\ obj \\ x86 \\ Debug \\ Circles.exe'不包含适用于入口点的静态'Main'方法Circles

The Properties build action is set to compile, but the Startup Object in the Project roperties is not set, is this causing the problem, if so what can I do? 属性构建操作设置为编译,但项目属性中的启动对象未设置,这是否导致问题,如果是,我该怎么办?

EDIT: Question resolved see CharithJ's answer below. 编辑:问题已解决,请参阅下面的CharithJ的答案。 Thanks Guys. 多谢你们。

You need to add the public access modifier to the class and the main method, and make main begin with an upper-case m: 您需要将public访问修饰符添加到类和main方法,并使main以大写m开头:

public class Program
{
    public static void Main(string[] args)
    {
        MessageBox.Show("Hello World!");

    }
}

Edit: As per comments, neither public access modifier is actually required. 编辑:根据评论,实际上既不需要公共访问修饰符。

You need to set the 'Startup Object' to be your Program class. 您需要将“启动对象”设置为您的Program类。

Windows applications (that is applications with an output type of 'Windows Application') typically have an entry point that looks like this: Windows应用程序(即输出类型为“Windows应用程序”的应用程序)通常具有如下所示的入口点:

    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new SomeForm());
    }

Whilst a 'Console Application' will typically have an entry such as: 虽然“控制台应用程序”通常会有一个条目,例如:

    public static void Main(string[] arguments)
    {
        ...
    }

Change static void main(string[] args) to public static void Main(string[] args) . static void main(string[] args)更改为public static void Main(string[] args)

Its Main not main . 它的Main不是main Uppercase M . 大写字母M

main method name should be Main main方法名称应为Main

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms;

namespace Circles 
{ 
    public class Program 
    { 
        public static void Main(string[] args) 
        { 
            MessageBox.Show("Hello World!");
        }
   }
}

change to 改成

static void Main(string[] args)

(captial 'M') (资本'M')

You don't need to make it public. 你不需要公开它。

您是否有任何特定原因在Visual Studio中不使用Windows窗体应用程序模板?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM