-2
안녕하세요, 내 클래스의 인수로 생성자를 전달하는 데 문제가 있습니다. 나는이 (Game1
클래스)처럼 인스턴스에 노력하고있어인수를 사용하여 생성자를 전달 하시겠습니까?
// Non-static variables exist once for each instance of the class
Vector2 position;
public Vector2 Position { get { return position; } }
public myClass(Vector2 position)
{
this.position = position;
}
: 거기는
myClass myClassInstance;
protected override void Initialize()
{
// TODO: Add your initialization logic here.
myClassInstance = new myClass(Position);
base.Initialize();
}
하지만 Initialize()
에서이 오류를 얻을 :
Error 1 The name 'Position' does not exist in the current context
난 당신이 여기에 뭘 하려는지 모르겠어요. 귀하의 초기화() 있음 거기에 당신에게 그 오류를주는 이유는 위치 변수라는 것 같지 않습니다. – Haedrian
@Haedrian은 Game1 클래스에 있습니다. 나는이 코드를 위해이 대답을 사용했다. http://stackoverflow.com/a/11383467/3944196 – PowerUser
정말 도움이 필요하다. – PowerUser