gpt4 book ai didi

c# - 错误消息 "CS5001 Program does not contain a static ' Main' 方法适用于入口点”,有多个类

转载 作者:行者123 更新时间:2023-12-02 10:42:01 25 4
gpt4 key购买 nike

所以这是交易,我目前有 2 个类(计划添加多个),当我尝试从这两个类调用函数时出现此错误。相同的命名空间。我仔细检查并查看我的属性选项卡,看看它已设置为编译。

using System;

namespace Game
{
public class SecondSet
{

public void SituationSecondOne()
{
Console.WriteLine(" ");
Console.WriteLine("Choices:");
Console.WriteLine("1: First");
Console.WriteLine("2: Second");
Console.WriteLine(" ");

int ChoiceOne = Convert.ToInt32(Console.ReadLine());

switch (ChoiceOne)
{
case (1):
Console.WriteLine("TEST2");
break;
case (2):
Console.WriteLine("TEST2");
break;
case (1337):
Console.WriteLine(" ");
Console.WriteLine("Thank you for playing");
Console.ReadLine();
Environment.Exit(1);
break;
default:
Console.WriteLine(" ");
Console.WriteLine("Now, let's try that again ... (¬_¬)");
SituationSecondOne();
break;
}
}
}
}

现在,当我从第二个到第一个调用该函数时,我没有收到任何错误。我需要什么类型的 Main() 方法? (我也试过把原来的public void Main(string[] args)加进去,加了之后就不能再把public加到我要调用的函数里了头等舱)

注意:我在第一个类中添加了这个

SecondSet s2 = new SecondSet();

上面发布了代码,它工作正常,但我得到了提到的编译错误。阀门请修复 :/

最佳答案

不清楚你的意思。但是我也在研究这个问题,就我而言,解决方案太简单了。我在解决方案中添加了一个新的空项目。新添加的项目会自动设置为控制台应用程序。但是由于添加的项目是一个“空”项目,因此该新项目中不存在 Program.cs。 (如预期)

我需要做的就是将项目属性的输出类型更改为类库

将项目>属性下的输出类型更改为“类库”。默认情况下,此设置可能已设置为“控制台应用程序”。

   static void Main()
{
}

关于c# - 错误消息 "CS5001 Program does not contain a static ' Main' 方法适用于入口点”,有多个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51017896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com