Guest User

Untitled

a guest
Jan 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. int[] indexes = input.Select((item, index) => new { item, index })
  2. .Where(x => x.item == "A")
  3. .Select(x => x.index)
  4. .ToArray();
  5.  
  6. public static int FindIndex<T>(
  7. T[] array,
  8. int startIndex,
  9. Predicate<T> match)
  10.  
  11. public static List<Int32> IndicesOf<T>(this T[] array, T value)
  12. {
  13. var indices = new List<Int32>();
  14.  
  15. Int32 startIndex = 0;
  16. while (true)
  17. {
  18. startIndex = Array.IndexOf<T>(array, value, startIndex);
  19. if (startIndex != -1)
  20. {
  21. indices.Add(startIndex);
  22. startIndex++;
  23. }
  24. else
  25. {
  26. break;
  27. }
  28. }
  29.  
  30. return indices;
  31. }
  32.  
  33. var symbols = new Char[] { 'a', 'b', 'c', 'a' };
  34. var indices = symbols.IndicesOf('a');
  35. indices.ForEach(index => Console.WriteLine(index));
Add Comment
Please, Sign In to add comment