Only if you have List<T>
:
All mentioned algorithms with SingleOrDefault()
/ FirstOrDefault()
require two passes among the list:
1) first find the item by criteria
2) the second, to find the index of the element by its value found in step # 1
It will be more effective than this:
int index = list.FindIndex(i => criteria); if (index >= 0) list.RemoveAt(index);
source share