更新时间:2023-11-25 23:09:16
这要看具体情况的需要。例如,字典的方法是相当不错的假设:
It depends on the needs of the specific situation. For example, the dictionary approach would be quite good assuming:
如果以上都不是真正适合您的情况,只需使用 任何()
:
If the above are not true for your situation, just use 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.