Improve the LINQ query returning indexes of items meeting a certain condition

I have this LINQ query which returns the indexes of all the items in an array whose time value (which is a double) meets a certain condition as in the below 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 pretty sure that this can be improved but how? I am stumped. Can anyone help me in this?

Answers


I don't see anything particularly wrong with that, in what way does it need to be better? If you want a reusable method for this kind of thing, see: Getting a collection of index values using a LINQ query


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

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

Need Your Help

I'm trying to create a sliding gallery in AS3 in Flash CS5, but I get these errors: does it have something to do with AS3 ?

actionscript-3 flash adobe flash-cs5

Scene 3, Layer 'AS', Frame 1, Line 1 1119: Access of possibly undefined property onEnterFrame through a reference with static type flash.display:DisplayObject. Scene 3, Layer 'AS', Frame...

how to close a oledbconnection object?

c# ado.net

ok so i have a Class A that implements method M1 that takes an excel path and a sheet name, and returns an OledbDataReader .

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.