ReadOnlyCollectionExtensions.cs 555 B

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