Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] indexes = input.Select((item, index) => new { item, index })
- .Where(x => x.item == "A")
- .Select(x => x.index)
- .ToArray();
- public static int FindIndex<T>(
- T[] array,
- int startIndex,
- Predicate<T> match)
- public static List<Int32> IndicesOf<T>(this T[] array, T value)
- {
- var indices = new List<Int32>();
- Int32 startIndex = 0;
- while (true)
- {
- startIndex = Array.IndexOf<T>(array, value, startIndex);
- if (startIndex != -1)
- {
- indices.Add(startIndex);
- startIndex++;
- }
- else
- {
- break;
- }
- }
- return indices;
- }
- var symbols = new Char[] { 'a', 'b', 'c', 'a' };
- var indices = symbols.IndicesOf('a');
- indices.ForEach(index => Console.WriteLine(index));
Add Comment
Please, Sign In to add comment