Improve LINQ query returning indexes of elements satisfying a certain condition

I have this LINQ query that returns the indices of all the elements in an array whose time value (which is equal double) matches a certain condition, as in the following query.

var sonicIndices = completeLog.Select((item, index) => new { Item = item, Index = index })
            .Where(x => Math.Abs(x.Item.time - nullValue) > 0.001)
            .Select(item => item.Index).ToArray();

I am sure that this can be improved, but how? I'm at a dead end. Can someone help me with this?

+3
source share
2 answers

I do not see anything special in this, how should it be better? If you want to use the reuse method for this kind of thing, see Getting a collection of index values ​​using LINQ query

+5
source

Not an improvement, but just another way to do the same:

var sonicIndices = Enumerable.Range(0, completeLog.Length)
                   .Where(i => Math.Abs(completeLog[i].time - nullValue) > 0.001)
                   .ToArray();
+3
source

All Articles