c# - 找不到类型或命名空间(是否缺少 using 指令或程序集引用?)

标签 c# .net using-directives

当我尝试编译我的 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();
    }

    }
}

错在哪里?我做错了什么?

最佳答案

当我的项目 .net 框架版本与我链接到的 DLL 的框架版本不匹配时,我收到此错误。就我而言,我得到了:

“找不到类型或命名空间名称‘UserVoice’(是否缺少 using 指令或程序集引用?)。

UserVoice 是 .Net 4.0,我的项目属性设置为“.Net 4.0 Client Profile”。在项目上更改为 .Net 4.0 清除了错误。我希望这对某人有所帮助。

关于c# - 找不到类型或命名空间(是否缺少 using 指令或程序集引用?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2721351/

相关文章:

c# - 检查列表 <> 项目,如果它包含相同的项目,则复制它们并将其从列表 <> 中删除

C# 创建 Excel(完成)然后显示/打开它?帮助

.net - 从 VS2010 升级到 VS2012 后,Linq to EF Join 抛出 "Index was out of range"

c# - 在 ToString() 方法中使用 lock() 进行集合

c# - .ToBitmap : Missing 'Using Directive' or 'Assembly Reference'

c# - 具有多种字体属性的文本 block 文本

c# - Activator.CreateInstance MissingMethodException 异常

c# - 我如何最小起订量 System.IO.FileInfo 类...或任何其他没有接口(interface)的类?

c++ - 结构/类声明中的作用域使用指令?

c++ - : "using namespace"?的目的是什么