我不确定我在这里做错了什么。我尝试过Console.Read();, Console.ReadLine();,但也没有。我也尝试过Ctrl F5。在搜索过程中,我没有找到其他建议。如果相关,我正在使用Visual Studio Express。显然,我试图让程序说,"Hello world!“下面是我的代码:
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
发布于 2012-11-19 00:18:25
该方法必须以大写M命名为Main,才能成为程序的“入口点”。
此外(感谢注释),您的最后一个using指令指向一个不存在的名称空间。mscorlib程序集中存在的命名空间取决于您使用的.NET版本。为此,您唯一需要的using是using System;。
此外,根据问题的更新,在同一解决方案中有两个包含Main()方法的类,即class Hello_World_和class Program。为了进行编译,您必须设置哪个Main()是启动方法(入口点)。在Visual Studio的右侧,右键单击要设置为启动项目的解决方案中的项目(或类)。
发布于 2012-11-19 00:19:54
您的项目可能没有使用控制台应用程序模板。(Here's how that works when creating a new project)
如果未使用上述方法创建项目,请确保将程序的输出类型设置为控制台应用程序,并将启动对象设置为Miscellaneous.Hello_World_
您可以在项目属性中设置输出类型和启动对象:
https://stackoverflow.com/questions/13441878
复制相似问题