I have been searching for hours and I just can't seem to find any kind of answers. I'm trying to make foreach
loop use a method inside of my object. Hopefully you can understand and help me.
Warrior.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
}