I'm trying to creat a delete character in a text game, this code would use a way were the player use his Character ID to delete the character, the ID is the position +1 in the list, but for now i can't delete the character because it's says that is out of bounds.
public static void DeletarJogador()
{
int ID;
Console.WriteLine("Characters resting at barracks: \n");
foreach(Player p in Listas.jogadores)
{
Console.WriteLine($">Name: {p.NomePlayer} ID: {p.IDPlayer}");
Console.WriteLine();
}
while(true)
{
Console.Write("Choose a character to delete, by ID: ");
ID = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Listas.jogadores.Count);
for(int i = 0 ; i <= Listas.jogadores.Count; i++)
{
Console.WriteLine(Listas.jogadores.Count);
if(ID == Listas.jogadores[i].IDPlayer)
{
Listas.jogadores.RemoveAt(ID);
}
}
break;
}
}