简体   繁体   中英

C# Connecting 2 Projects

I downloaded a Sudoku game in C# and I am trying to connect that game with my project but when I try to connect it with :

private void button4_Click(object sender, EventArgs e)
    {
        Sudoku.SudokuMainForm a = new Sudoku.SudokuMainForm();
        a.Show();
        Hide();
    }

It tells me that Sudoku is a namespace but is used like a type.

Here is the part where I have problems with.

namespace Sudoku
{

    public class SudokuMainForm : System.Windows.Forms.Form


        }
        Sudoku _newGame = new Sudoku();

        private void btnAnswer_Click(object sender, System.EventArgs e)
        {
            _showAnswer = false;
            ShowAnswer();
            timer1.Enabled = true;


        }

Tried the whole day to fix it,but can't find the solution for my problem. Hope that you guys have an idea. Thanks

Here is the problem, you are trying the create instance from name space. Just create instance of any necessary class defined within this name space. you can not create instance with a namespace.

Sudoku _newGame = new Sudoku();

Your form is in a namespace called Sudoku, and you are trying to instantiate a class called Sudoku.

You have 2 options, either change your namespace (this is probably simpler, so instead of "namespace Sudoku", try "namespace MySudoku" or something.

Or use:

var _newGame = global::<namespace_of_Sudoku_game>.Sudoku();

(assuming that your Sudoku class is in SudokuGame then: new global::SudokuGame.Sudoku() )

如果在名称空间内使用具有相同名称的类,则需要同时声明两者或使用名称空间别名:

Sudoku.Sudoku _newGame = new Sudoku.Sudoku();

I did it. Right Click on Solution>Add>Existing Project>Selecting the.csproj>Right Click on the first project>Add References>Selected the added project> and then the normal binding. Thanks for everyone help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM