我是新手程序员,我需要一些帮助来理解错误。 我创建了一个对象,我在其中创建我的玩家的构造函数。然而,只要我完成我的构造函数,其他所有对象都是空的。对象不可能创建对象吗?如果不是,我该如何设计我的程序,以便我可以从任何课程中访问我的播放器对象。在构造函数中创建的对象变为空
class Program
{
static void Main(string[] args)
{
Tablero tablero = new Tablero();
tablero.test(); //now Tablero doesnt have player
Console.ReadLine();
}
public class Tablero
{
Buscador busc1;
public Tablero()
{
Buscador busc1 = new Buscador(50);
//test(); same problem
}
public void test()
{
Console.Write(busc1.getPosX());
}
}
public class Buscador
{
int posx;
public Buscador(int posx)
{
this.posx = posx;
}
public int getPosX()
{
return posx;
}
}
}
提示:看看编译器_warnings _... –