当我尝试编译我的源代码时,它给了我这个错误。当我从 Visual Studio 运行程序时,它可以工作。我目前正在为我和我的 friend 创建一个 windows 窗体纸牌游戏。这是我的主要 Program.cs 文件。
错误:
Program.cs(16,33): error CS0246: The type or namespace name 'Bussen' could not be found (are you missing a using directive or an assembly reference?)
代码:
using System;
using System.Windows.Forms;
using bussen;
namespace bussen
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Bussen());
}
}
}
另一个文件名为 forms1.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using bussen;
namespace bussen
{
public partial class Bussen : Form
{
public List<string> allCards = new List<string> { };
public List<string> CardsColour = new List<string> { };
public Bussen()
{
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
InitializeComponent();
LoadCards();
}
private void SelectCard(object sender, EventArgs e)
{
Random rnd = new Random();
int RandomNumber = rnd.Next(0, allCards.Count);
try
{
if (CardsColour.IndexOf(allCards[RandomNumber]) < 26)
{
(sender as Button).ForeColor = System.Drawing.Color.Black;
}
else
{
(sender as Button).ForeColor = System.Drawing.Color.Red;
}
(sender as Button).Text = allCards[RandomNumber];
allCards.Remove(allCards[RandomNumber]);
}
catch
{
LoadCards();
}
}
public void LoadCards()
{
StreamReader streamreader = new StreamReader(@"cards.txt");
string line;
while ((line = streamreader.ReadLine()) != null)
{
allCards.Add(line);
if (CardsColour.Count < 52)
{
CardsColour.Add(line);
}
}
streamreader.Close();
}
private void Restart(object sender, EventArgs e)
{
Application.Restart();
}
}
}
最佳答案
我应该在编译时提供多个文件名
-它是[scs“program.cs”]
- 但应该是 [csc "program.cs""Form1.cs""Form1.Designer.cs"]
关于c# - 找不到类型或命名空间名称 'Bussen'(您是否缺少 using 指令或程序集引用?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61124052/