score:8
ienumerable<priorelemst> priorselemlst = priorslstids.select((s,i) => new priorelemst(s, priorslstdates[i]));
return filterstudypriors(priorselemlst);
score:2
it is not a best practice at all but only if you think it will improve the readability against a performance loss.
linq-to-objects generally is going to add some marginal overheads (multiple iterators, etc). it still has to do the loops, and has delegate invokes, and will generally have to do some extra dereferencing to get at captured variables etc.
score:4
you can use the zip method
var priorselemlst = priorslstids.zip(
priorslstdates, (i, d) => new priorelemst(i, d))
in the above statement i
is the item from priorslstids and d
the item from priorslstdates. they will be 'zipped' together using their positions in their lists.
score:4
you could use the enumerable.range method like so:
//first get the range of indexes
var range = enumerable.range(0, priorslstids.count);
//now project a list of elements at each index
var priorselemlst = range.select(i => new priorelemst(priorslstids[i], priorslstdates[i])).tolist();
Source: stackoverflow.com
Related Query
- How can I switch that code to use LINQ
- How can I use Left join in linq that we use in sql?
- How can I use linq to return integers in one array that do not match up with an integer property of another array?
- How can I use LINQ with a class that has parallel arrays?
- How can I use LINQ to retrieve entries that contain a specific property of a list within a list?
- How can I use LINQ to retrieve entries that contain more than one property of a list within a list?
- How can I use a LINQ statement to filter out items that matches one of the words from another List?
- How can I take the information I received with linq and use that information in an if else statement?
- How can I use Linq in a T4 template?
- How are people unit testing code that uses Linq to SQL
- How can I implement NotOfType<T> in LINQ that has a nice calling syntax?
- How can I use linq to sort by multiple fields?
- How can I use LINQ to find a DataGridView row?
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1
- How can I use Linq with a MySql database on Mono?
- How can I use linq to initialize an array of repeated elements?
- The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation
- How can I use LINQ to project this parent and children object model into a flat, single object?
- How can you see the sql that is causing an error on SubmitChanges in LINQ to SQL?
- How can I update in Linq an entity that is disconnected from database?
- How does this linq code that splits a sequence work?
- How can I use linq to check if an flags/bitwise enumeration contains a type?
- How can I use LINQ to calculate the longest streak?
- How to use Func in a linq query that provide an IQueryable output
- How can I combine this code into one or two LINQ queries?
- How can I use LINQ to "prune" a dictionary?
- How do I use Linq to find the elements of a list that are not present in another list?
- How can I use Linq to create an IEnumerable based on line breaks in a string?
- linq - how do you do a query for items in one query source that are not in another one?
More Query from same tag
- Best way to extract rows from DataTable (based on date field) and copy to another DataTable
- MongoDB C# driver fast on take(1) but slow on take(2)
- Correct Join statement in Linq
- Using LINQ to pull collection until aggregate condition met
- How to convert List<string> to xml
- Add an index to a list to show a ranking from 1 to max items in the list
- Write WHERE conditions with Enum values using AsQueryable in Entity Framework
- error: The query results cannot be enumerated more than once
- How to order IEnumerable based on a predefined sequence?
- Understanding the exception "An entity object cannot be referenced by multiple instances of IEntityChangeTracker."
- Linq result data binding - How to change the column header?
- LINQ Select distinct on different variables
- FindIndex extension in LINQ
- If a linq query returns empty does it return null?
- How to get all the rows of a table, where a column's value occurs more than once in LINQ to Entities?
- Populating a text box using MVVM/LINQ and XAML
- using LINQ to get a particular set of objects from a list of objects
- FInd items in JSON object using LINQ
- Linq, date comparison
- How to get Entity from DB including navigation properties and child list total amount
- C# LINQ to SQL Specified type member inside lambda expression
- Nested Lists in LINQ to SQL
- How to tell "OfType()" to ignore inherited classes?
- C# LINQ for tree oriented data structure of classes
- Merge different length arrays without losing a value using Zip()
- C# Sum of Values in a nested dictionary where value is a class Dictionary<string, Dictionary<Int16, CommonData>>
- How to group DataTable results using Linq query expression
- SQL Query to LINQ Lambda expression
- Method return data type when using LINQ to Entities
- How do I specify the Linq OrderBy argument dynamically?