找不到类型或命名空间(是否缺少 using 指令或程序集引用?)
当我尝试编译 C# 程序时,出现以下错误:
无法找到类型或命名空间名称“Login”(您是否缺少 using 指令或程序集引用?)
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 FootballLeague
{
public partial class MainMenu : Form
{
FootballLeagueDatabase footballLeagueDatabase;
Game game;
Team team;
Login login; //Error here
public MainMenu()
{
InitializeComponent();
changePanel(1);
}
public MainMenu(FootballLeagueDatabase footballLeagueDatabaseIn)
{
InitializeComponent();
footballLeagueDatabase = footballLeagueDatabaseIn;
}
private void Form_Loaded(object sender, EventArgs e)
{
}
private void gameButton_Click(object sender, EventArgs e)
{
int option = 0;
changePanel(option);
}
private void scoreboardButton_Click(object sender, EventArgs e)
{
int option = 1;
changePanel(option);
}
private void changePanel(int optionIn)
{
gamePanel.Hide();
scoreboardPanel.Hide();
string title = "Football League System";
switch (optionIn)
{
case 0:
gamePanel.Show();
this.Text = title + " - Game Menu";
break;
case 1:
scoreboardPanel.Show();
this.Text = title + " - Display Menu";
break;
}
}
private void logoutButton_Click(object sender, EventArgs e)
{
login = new Login();
login.Show();
this.Hide();
}
Login .cs
类:
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 FootballLeagueSystem
{
public partial class Login : Form
{
MainMenu menu;
public Login()
{
InitializeComponent();
}
private void administratorLoginButton_Click(object sender, EventArgs e)
{
string username1 = "08247739";
string password1 = "08247739";
if ((userNameTxt.Text.Length) == 0)
MessageBox.Show("Please enter your username!");
else if ((passwordTxt.Text.Length) == 0)
MessageBox.Show("Please enter your password!");
else if (userNameTxt.Text.Equals("") || passwordTxt.Text.Equals(""))
MessageBox.Show("Invalid Username or Password!");
else
{
if (this.userNameTxt.Text == username1 && this.passwordTxt.Text == password1)
MessageBox.Show("Welcome Administrator!", "Administrator Login");
menu = new MainMenu();
menu.Show();
this.Hide();
}
}
private void managerLoginButton_Click(object sender, EventArgs e)
{
{
string username2 = "1111";
string password2 = "1111";
if ((userNameTxt.Text.Length) == 0)
MessageBox.Show("Please enter your username!");
else if ((passwordTxt.Text.Length) == 0)
MessageBox.Show("Please enter your password!");
else if (userNameTxt.Text.Equals("") && passwordTxt.Text.Equals(""))
MessageBox.Show("Invalid Username or Password!");
else
{
if (this.userNameTxt.Text == username2 && this.passwordTxt.Text == password2)
MessageBox.Show("Welcome Manager!", "Manager Login");
menu = new MainMenu();
menu.Show();
this.Hide();
}
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
错误在哪里?我做错了什么?
I get the following error when I try to compile my C# program:
The type or namespace name 'Login' could not be found (are you missing a using directive or an assembly reference?)
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 FootballLeague
{
public partial class MainMenu : Form
{
FootballLeagueDatabase footballLeagueDatabase;
Game game;
Team team;
Login login; //Error here
public MainMenu()
{
InitializeComponent();
changePanel(1);
}
public MainMenu(FootballLeagueDatabase footballLeagueDatabaseIn)
{
InitializeComponent();
footballLeagueDatabase = footballLeagueDatabaseIn;
}
private void Form_Loaded(object sender, EventArgs e)
{
}
private void gameButton_Click(object sender, EventArgs e)
{
int option = 0;
changePanel(option);
}
private void scoreboardButton_Click(object sender, EventArgs e)
{
int option = 1;
changePanel(option);
}
private void changePanel(int optionIn)
{
gamePanel.Hide();
scoreboardPanel.Hide();
string title = "Football League System";
switch (optionIn)
{
case 0:
gamePanel.Show();
this.Text = title + " - Game Menu";
break;
case 1:
scoreboardPanel.Show();
this.Text = title + " - Display Menu";
break;
}
}
private void logoutButton_Click(object sender, EventArgs e)
{
login = new Login();
login.Show();
this.Hide();
}
Login.cs
class:
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 FootballLeagueSystem
{
public partial class Login : Form
{
MainMenu menu;
public Login()
{
InitializeComponent();
}
private void administratorLoginButton_Click(object sender, EventArgs e)
{
string username1 = "08247739";
string password1 = "08247739";
if ((userNameTxt.Text.Length) == 0)
MessageBox.Show("Please enter your username!");
else if ((passwordTxt.Text.Length) == 0)
MessageBox.Show("Please enter your password!");
else if (userNameTxt.Text.Equals("") || passwordTxt.Text.Equals(""))
MessageBox.Show("Invalid Username or Password!");
else
{
if (this.userNameTxt.Text == username1 && this.passwordTxt.Text == password1)
MessageBox.Show("Welcome Administrator!", "Administrator Login");
menu = new MainMenu();
menu.Show();
this.Hide();
}
}
private void managerLoginButton_Click(object sender, EventArgs e)
{
{
string username2 = "1111";
string password2 = "1111";
if ((userNameTxt.Text.Length) == 0)
MessageBox.Show("Please enter your username!");
else if ((passwordTxt.Text.Length) == 0)
MessageBox.Show("Please enter your password!");
else if (userNameTxt.Text.Equals("") && passwordTxt.Text.Equals(""))
MessageBox.Show("Invalid Username or Password!");
else
{
if (this.userNameTxt.Text == username2 && this.passwordTxt.Text == password2)
MessageBox.Show("Welcome Manager!", "Manager Login");
menu = new MainMenu();
menu.Show();
this.Hide();
}
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Where is the error? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当我的项目 .net 框架版本与我链接到的 DLL 的框架版本不匹配时,我会收到此错误。就我而言,我得到:
“找不到类型或命名空间名称“UserVoice”(您是否缺少 using 指令或程序集引用?)。
UserVoice 是 .Net 4.0,我的项目属性设置为“。 Net 4.0 客户端配置文件”。在项目上更改为 .Net 4.0 清除了错误。我希望这对某人有帮助。
I get this error when my project .net framework version does not match the framework version of the DLL I am linking to. In my case, I was getting:
"The type or namespace name 'UserVoice' could not be found (are you missing a using directive or an assembly reference?).
UserVoice was .Net 4.0, and my project properties were set to ".Net 4.0 Client Profile". Changing to .Net 4.0 on the project cleared the error. I hope this helps someone.
您没有 Login 类所在的命名空间作为引用。
将以下内容添加到使用
Login
类的表单中:当您想要在另一个 命名空间,你必须告诉编译器在哪里找到它。在本例中,
Login
位于FootballLeagueSystem
命名空间内,或者:FootballLeagueSystem.Login
是完全限定的命名空间。正如评论者指出的那样,您在
FootballLeagueSystem
命名空间内声明了 Login 类,但您在FootballLeague
命名空间中使用它。You don't have the namespace the Login class is in as a reference.
Add the following to the form that uses the
Login
class:When you want to use a class in another namespace, you have to tell the compiler where to find it. In this case,
Login
is inside theFootballLeagueSystem
namespace, or :FootballLeagueSystem.Login
is the fully qualified namespace.As a commenter pointed out, you declare the Login class inside the
FootballLeagueSystem
namespace, but you're using it in theFootballLeague
namespace.您需要将以下行添加
到所有使用
Login
的类(MainMenu.cs、programme.cs 等)中。目前编译器找不到
Login
类。You need to add the following line:
into your all your classes (MainMenu.cs, programme.cs, etc.) that use
Login
.At the moment the compiler can't find the
Login
class.如果您在项目中的单独文件夹中登录,请确保您在使用它的位置执行:
using FootballLeagueSystem.[无论您使用的文件夹]
If you have Login in a seperate folder within your project make sure that where you are using it you do:
using FootballLeagueSystem.[Whatever folder you are using]
这个错误是因为编译不知道在哪里找到该类..所以它主要发生在你复制或导入项目..解决这个问题..
1.将formname.cs和formname.designer.cs中的命名空间更改为您的项目名称。
This error comes because compile does not know where to find the class..so it occurs mainly when u copy or import item ..to solve this ..
1.change the namespace in the formname.cs and formname.designer.cs to the name of your project .
如果您键入包含该类的文件的名称而不是该类的名称,也可能会发生此错误。例如,您有一个名为 login 的文件,但文件中的类名为 LB,并且您引用文件的名称“login”,但不是其中的类的名称“LB”
This error can also happen if you type the name of the file containing the class and not the name of the class. For example you have a file named login but your class inside the file is named LB, and you reference the name of the file, "login" but not the name of the class inside it, "LB"