私は何時間も探していましたが、何の答えも見つからないようです。foreach
オブジェクト内のメソッドを使用してループを作成しようとしています。うまくいけば、あなたは私を理解して助けてくれるでしょう。
戦士.cs:
public void Info()
{
Console.WriteLine("N: "
+ this.name
+ ", L: "
+ this.level
+ ", H: "
+ this.health
+ ", D: "
+ this.damage
+ ", A: "
+ this.agility);
}
Program.cs:
List<Warrior> lista = new List<Warrior>();
for (int i = 0; i < 10; i++)
{
lista.Add(new Warrior("Swordman" + i.ToString()));
}
foreach (Warrior item in lista)
{
lista.Info();//<----------This is where I get the error
}