score:6
Accepted answer
return enumerable.Select((e, i) => new KeyValuePair<int, T>(i, e));
Also note that your approach using i++
as a captured variable is not safe; someone could call Count()
first, for example - of use Parallel
.
Source: stackoverflow.com
Related Query
- Is there a Linq function that returns indices?
- Is there a good source that gives an overview of linq optimizations?
- Linq How to perform Subquery with max function that returns a primitive value such as an integer?
- Is there a way I can do a foreach that contains code in a LINQ expression?
- How to write SQL translateable linq code that groups by one property and returns distinct list
- How are people unit testing code that uses Linq to SQL
- Is there a LINQ function for getting the longest string in a list of strings?
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- Sending items in a LINQ sequence to a method that returns void
- Is there a library that provides a formatted Dump( ) function like LinqPad?
- Is there a simple way to write a custom function in LINQ to Entities?
- Is there a LINQ extension or (a sensible/efficient set of LINQ entensions) that determine whether a collection has at least 'x' elements?
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Is there a JS library that supports writing linq to sql queries with nodejs?
- LINQ Source Code Available
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- Linq .Sum() function fails when there is nothing to Sum
- Is there a way to speed up this code that finds data changes in two XML files?
- linq - how do you do a query for items in one query source that are not in another one?
- Is there a way to return only the function calls that do not throw exceptions with LINQ?
- Is there anything that is possible in LINQ but not Lambda?
- Is there a bug in this code from 101 LINQ Samples on MSDN? (Update: Fixed)
- Custom jQuery Selector That Returns Selected Element Properties Like LINQ
- How to code the partial extensions that Linq to SQL autogenerates?
- LINQ query returns old results when source list is re-initialized
- Is there a Linq method that does .SelectMany(x => x)?
- creating Linq to sqlite dbml from DbLinq source code
- Is there a way to create an Linq XElement iterator that is updated as the tree is modified?
- GroupByUntilChanged: is there a LINQ GroupBy operator that groups by SUCCESSIVE equal keys?
More Query from same tag
- LINQ to Xml list wrong query
- Equals Override and LINQ GroupBy
- C# Dynamic linq Contains method with parameter
- Check if each object of list is present in another list
- LINQ Error: Method not recognized
- C# How to make recursive function to return the nth most common integer in an array of integers
- How can I order query by SelectListItem?
- LINQ to SQL displayed in console mode app
- How-to ensure multiple collections have the same item count using LINQ
- LINQ to List<> to String - Best Optimized Method
- Linq Query to filter Table 1 and get count from Table 2
- Group by one table and sum from another table in Linq
- C# xml linq query results formatting
- Creating xml with xdocument
- How to convert an Int to a String inside a LINQ query
- Linq output multiply results
- Writing an anonymous method for a method in IEnumerable
- Nested classes lists LINQ
- How to convert Object to Dictionary in JSON.Net?
- C#: How can I filter the results of an XML file based on a child element's attribute?
- How do I update a field of a record using linq
- How to do a LINQ query for count of entity whose owner == current user?
- C# LINQ query to return matching characters or whole words like Google Search
- what is the best way to convert one dictionary to another
- Distinct Date with Linq
- Database records added to top of table instead of bottom using LINQ
- How to calculate sum() column from dynamic list?
- Linq query not giving desired results
- Mediator Helper class in Vb.net
- WCF/REST hash/salt datamember field