我有一个问题,我要声明一个公共类和结构,然后必须从我的 main 运行一个函数,并且不能从 main 声明类和结构内的变量。因此,由于“方法没有重载”错误,该函数将无法工作。我将如何解决这个问题?我觉得好像我错过了一些非常简单但看不到的东西。
提前致谢。如果您需要任何进一步的信息来帮助我,请不要犹豫。
public struct CellReference
{
private int CNorth, CEast;
public int CellsNorth
{
get
{
return CellsNorth;
}
set
{
CNorth = value;
}
}
public int CellsEast
{
get
{
return CellsEast;
}
set
{
CEast = value;
}
}
}
static void Main(string[] args)
{
Piece black1, black2, black3, black4, black5, black6, black7, black8, black9, black10, black11, black12, white1, white2, white3, white4, white5, white6, white7, white8, white9, white10, white11, white12;
StartGame();
Console.ReadKey();
}
public class Piece
{
public CellReference Location;
public bool isBlack;
public bool isKing;
}
基本上我无法初始化 StartGame() 需要的一些变量。
那么 StartGames 是这样的:
static void StartGame(ref int CNorth, ref int CEast, ref bool isKing, ref bool isBlack, ref int CellsEast, ref int CellsNorth, ref Piece black1, ref Piece black2, ref Piece black3, ref Piece black4, ref Piece black5, ref Piece black6, ref Piece black7, ref Piece black8, ref Piece black9, ref Piece black10, ref Piece black11, ref Piece black12, ref Piece white1, ref Piece white2, ref Piece white3, ref Piece white4, ref Piece white5, ref Piece white6, ref Piece white7, ref Piece white8, ref Piece white9, ref Piece white10, ref Piece white11, ref Piece white12)
但是,如果我在 main 中调用 StartGame(),如果我将所有引用都放入它不起作用,因为它们不在 Main 中。