问题描述
我收到以下错误,当我尝试编译我的C#程序:
I get the following error when I try to compile my C# program:
类型或命名空间名称'登录'找不到(是否缺少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
类:
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?
推荐答案
您没有登录类是作为参考的命名空间。
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:
using FootballLeagueSystem;
当你想在其他使用类的,你必须告诉编译器在哪里可以找到它。在这种情况下,登录
是 FootballLeagueSystem
命名空间中,或: FootballLeagueSystem.Login
是完全合格的命名空间的。
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 the FootballLeagueSystem
namespace, or : FootballLeagueSystem.Login
is the fully qualified namespace.
作为一个评论者指出的那样,你声明的 FootballLeagueSystem
命名空间内登录类,但你使用它的 FootballLeague
命名空间。
As a commenter pointed out, you declare the Login class inside the FootballLeagueSystem
namespace, but you're using it in the FootballLeague
namespace.
这篇关于类型或命名空间无法找到(是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!