C
C#6mo ago
SY

✅ which is better ?

So I have class Room and I’m trying to do some optomization I created a List of room and then created a function that makes a loop in the list and return the room if it matches the id. Now thinking about it i can also make a Dictionary<int, room> and access room with the id which one is better ?
2 Replies
Pobiega
Pobiega6mo ago
Dictionary access is faster than looping over a list. The difference is minimal for small numbers of items, but as your collection grows the list loop access time will grow several orders of magnitude faster than dictionary
SY
SY6mo ago
Ty