public void showStats(string player)
{
foreach (playerData playerstats in Program.playerList)
{
if (playerstats._playerName == player)
{
Console.WriteLine();
Console.WriteLine("Player Name: {0}", playerstats._playerName);
Console.WriteLine("Player ID: {0}", playerstats._playerID);
Console.WriteLine("Player Level: {0}", playerstats._playerLevel);
Console.WriteLine("Player Land: {0}", playerstats._playerLand);
Console.WriteLine("Player Peasants: {0}", playerstats._playerPeasants);
Console.WriteLine("Player Moves: {0}", playerstats._playerMoves);
Console.WriteLine("Player Copper: {0}", playerstats._playerCopper);
Console.WriteLine("Player Castles: {0}", playerstats._playerCastles);
Console.WriteLine();
}
}
}
Now, just one look at this code makes me cringe because it doesn't seem at all efficient in any sense of the word, to iterate over a list to obtain the correct reference to the object I wish to display but this is how I got it to work. Is there a better way of doing this?
Replies
Know the answer? Post it — somebody with the same question will find it here.