ReadOnlyCollectionExtensions.cs 694 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace Terminal.Gui;
  2. internal static class ReadOnlyCollectionExtensions
  3. {
  4. public static int IndexOf<T> (this IReadOnlyCollection<T> self, Func<T, bool> predicate)
  5. {
  6. var i = 0;
  7. foreach (T element in self)
  8. {
  9. if (predicate (element))
  10. {
  11. return i;
  12. }
  13. i++;
  14. }
  15. return -1;
  16. }
  17. public static int IndexOf<T> (this IReadOnlyCollection<T> self, T toFind)
  18. {
  19. var i = 0;
  20. foreach (T element in self)
  21. {
  22. if (Equals (element, toFind))
  23. {
  24. return i;
  25. }
  26. i++;
  27. }
  28. return -1;
  29. }
  30. }