It depends on the needs of the specific situation. For example, the dictionary approach would be quite good assuming:
- The list is relatively stable (not a lot of inserts/deletions, which dictionaries are not optimized for)
- The list is quite large (otherwise the overhead of the dictionary is pointless).
If the above are not true for your situation, just use the method Any()
:
Item wonderIfItsPresent = ...
bool containsItem = myList.Any(item => item.UniqueProperty == wonderIfItsPresent.UniqueProperty);
This will enumerate through the list until it finds a match, or until it reaches the end.