Can linq somehow be used to find the index of a value in an array?
For instance, this loop locates the key index within an array.
for (int i = 0; i < words.Length; i++)
{
if (words[i].IsKey)
{
keyIndex = i;
}
}
Can linq somehow be used to find the index of a value in an array?
For instance, this loop locates the key index within an array.
for (int i = 0; i < words.Length; i++)
{
if (words[i].IsKey)
{
keyIndex = i;
}
}
int index = -1;
index = words.Any (word => { index++; return word.IsKey; }) ? index : -1;