Background:
I'm working on an evaluator (I know there's solutions available, but I need some features that I need to implement myself). I need to find all occurrences of open brackets in the evaluation. However, for that I need all the indexes of the brackets.
Question:
Is there something like an AllIndexesOf method that returns a int[]
, or IEnumerable<int>
?
There is not but you can get all the indexes using the following LINQ query.
int number = 10;
int[] intArray = new[] { 1, 32, 10, 5, 65, 6, 10, 10 };
var allIndexes = intArray.Select((r,i)=> new {value = r, index = i})
.Where(r=> r.value == number)
.Select(r=> r.index);
allIndexes
will contain 2,6 and 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With