に存在しません:それはPlayer
クラスでAttack()
内のコードの行を参照することだ変数は、現在のコンテキストだから、私はこれをエラーとして取得してい
The name
p1
does not exist in the current context.
。
namespace GameOne
{
public class Program
{
public static void Main()
{
Ai [] badguys = new Ai [5];
Player p1 = new Player();
}
}
public class Ai
{
public Ai()
{
int Health = 10;
int Damage = 1;
}
public static int Attack()
{
p1.Health--;
return p1.Health;
}
}
public class Player
{
public Player()
{
int Health = 50;
}
}
}
'p1'は' Main() 'のローカル変数です。 'Attack()'には 'p1'というシンボルが定義されていません。 – xxbbcc
コードを投稿するときは、コードを正しく確認して、インデントが一貫していることを確認し、読みやすくするために余分な空白行を削除してください。 – crashmstr
質問する前に、常にエラーをオンラインで検索してください。次の投稿が役立ちます。 https://stackoverflow.com/questions/41974155/the-name-does-not-exist-in-the-current-context –