Which is faster? ForEach or IndexOf.
Posted on 2006-11-15
Looking for some information on which method is faster. I'm using a List of Player objects, which rougly contains 10-40 Player objects when the function is called. Speed is an issue, as the socket itself is slow enough.
/// Handles player leaving the room.
/// <param name="token">StringTokenizer</param>
/// v,2859,1,Sp&AAPIrg Vicev&AAOGrt,
internal static void HandlePlayerLeaveRoom(int id, StringTokenizer token)
// Method 1
player = new Player(id);
// Method 2
// Check if player exists.
// Found match.
if (player.Id == id)
// Remove the player.
Thanks for reading.