R
raylopez99
I would like to know if there's a quick "Linq" way to find the index
of an array having a particular value. I can do this the long way by
sequential iteration, but would like to know if there's a shortcut.
Specifically, you have an Array, say an array of Ints. You have a
maximum value, i.e. int someValue = Array.Max(); and you would like to
know which ith cell of the Array holds this value.
How to do this without iterating the entire array (and counting the
indexes, etc, until you come across this value)?
Of course you an also set up a map/dictionary, and your index would be
the key, but I would like to do this for an ordinary array.
No big deal, but I'm just trying to optimize some code (I have a 300M
int array, and arguably the Linq way might be faster than traversing
sequentially the array, though perhaps I'm mistaken).
Thank you.
RL
of an array having a particular value. I can do this the long way by
sequential iteration, but would like to know if there's a shortcut.
Specifically, you have an Array, say an array of Ints. You have a
maximum value, i.e. int someValue = Array.Max(); and you would like to
know which ith cell of the Array holds this value.
How to do this without iterating the entire array (and counting the
indexes, etc, until you come across this value)?
Of course you an also set up a map/dictionary, and your index would be
the key, but I would like to do this for an ordinary array.
No big deal, but I'm just trying to optimize some code (I have a 300M
int array, and arguably the Linq way might be faster than traversing
sequentially the array, though perhaps I'm mistaken).
Thank you.
RL