gpt4 book ai didi

c# - "does not contain a static ' 主要 ' method suitable for an entry point"

转载 作者:太空狗 更新时间:2023-10-29 17:27:43 26 4
gpt4 key购买 nike

我想不出我下面的代码有什么问题。

当我尝试编译时,我收到消息:

does not contain a static 'main' method suitable for an entry point.

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RandomNumberGenerator
{

public partial class Form1 : Form
{
private const int rangeNumberMin = 1;
private const int rangeNumberMax = 3;
private int randomNumber;

public Form1()
{
randomNumber = GenerateNumber(rangeNumberMin, rangeNumberMax);
}

private int GenerateNumber(int min,int max)
{
Random random = new Random();
return random.Next(min, max);
}

private void Display(object sender, EventArgs e)
{
switch (randomNumber)
{
case 1:
MessageBox.Show("A");
break;
case 2:
MessageBox.Show("B");
break;
case 3:
MessageBox.Show("C");
break;
}

}
}
}

谁能告诉我哪里做错了。

最佳答案

每个 C# 程序都需要一个入口点。默认情况下,新的 c# Windows 窗体项目在 Program.cs 文件中包含一个 Program 类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StackOverflow6
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

您可能遗漏了它或删除了它。

关于c# - "does not contain a static ' 主要 ' method suitable for an entry point",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17095217/

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