首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >你好,世界!-- C#

你好,世界!-- C#
EN

Stack Overflow用户
提问于 2012-11-19 00:12:12
回答 2查看 2.2K关注 0票数 0

我不确定我在这里做错了什么。我尝试过Console.Read();, Console.ReadLine();,但也没有。我也尝试过Ctrl F5。在搜索过程中,我没有找到其他建议。如果相关,我正在使用Visual Studio Express。显然,我试图让程序说,"Hello world!“下面是我的代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Miscellaneous
{
    class Hello_World_
    {
        static void Main()
        {
            Console.WriteLine("Hello world!");
            Console.Read();
        }
    }
}

错误1 Program 'c:\Users\MyUserName\Desktop\Visual Studio Workspace\Miscellaneous\Miscellaneous\obj\Debug\Miscellaneous.exe' has more than one entry point defined: 'Miscellaneous.Hello_World_.Main()'. Compile with /main to specify the type that contains the entry point. C:\Users\MyUserName\Desktop\Visual Studio Workspace\Miscellaneous\Miscellaneous\Hello World!.cs 11 21 Miscellaneous

错误2 Program 'c:\Users\MyUserName\Desktop\Visual Studio Workspace\Miscellaneous\Miscellaneous\obj\Debug\Miscellaneous.exe' has more than one entry point defined: 'Miscellaneous.Program.Main()'. Compile with /main to specify the type that contains the entry point. C:\Users\MyUserName\Desktop\Visual Studio Workspace\Miscellaneous\Miscellaneous\Program.cs 15 21 Miscellaneous

EN

回答 2

Stack Overflow用户

发布于 2012-11-19 00:18:25

该方法必须以大写M命名为Main,才能成为程序的“入口点”。

此外(感谢注释),您的最后一个using指令指向一个不存在的名称空间。mscorlib程序集中存在的命名空间取决于您使用的.NET版本。为此,您唯一需要的usingusing System;

此外,根据问题的更新,在同一解决方案中有两个包含Main()方法的类,即class Hello_World_class Program。为了进行编译,您必须设置哪个Main()是启动方法(入口点)。在Visual Studio的右侧,右键单击要设置为启动项目的解决方案中的项目(或类)。

票数 3
EN

Stack Overflow用户

发布于 2012-11-19 00:19:54

您的项目可能没有使用控制台应用程序模板。(Here's how that works when creating a new project)

如果未使用上述方法创建项目,请确保将程序的输出类型设置为控制台应用程序,并将启动对象设置为Miscellaneous.Hello_World_

您可以在项目属性中设置输出类型启动对象

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13441878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档