score:11
Accepted answer
use var
instead of object
. the select new
creates an anonymous type:
foreach (var oparam in objlist)
{
console.writeline(oparam.userid);
}
score:4
you could also use a small extension method (credits):
public static void foreach<t>(this ienumerable<t> @this, action<t> action)
{
foreach (var item in @this)
action(item);
}
then you can do
objlist.foreach(oparam =>
{
... // your code here, e.g. console.writeline(oparam.userid)
}
it's really good in method-syntax linq.
Source: stackoverflow.com
Related Query
- How to loop through var object collection in C#?
- How to loop through a child list of objects in Entity Framework 4.1 code first
- How do I loop through a collection of LINQ to Entities collection?
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- How can I iterate through a collection with Foreach to build an XDocument?
- how to find minimum difference object of collection in c# linq
- How to loop through controls to get specific type of controls?
- How can I loop Through all the elements in .select statement in Linq
- How to Loop through Datatable in Linq?
- How to query ManagementObjectCollection with LINQ, then loop through PropertyData for returned ManagementObject?
- How to easly convert linq result to Business Object Collection <T>
- How to return first object of a collection from its parent
- How to enumerate through list of Func<TSource,TResult> to filter collection
- How do I use linq to do a WHERE against a collection object (using Netflix data source)
- How do I group by a property in an object collection using LINQ?
- How to remove selected data that found on another list and take last 6 id through LINQ without foreach loop
- How to change the precision and the scale of decimal globally through code first?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- How to get the second repeated item from a collection of objects using LINQ to object
- How to code a Foreach Loop for Endless Categories Tree in MVC.Net?
- How do I convert a recursive object to a Collection in C#?
- Loop and update object value in a collection using LINQ
- without for loop how can is show var type these value in TextBox
- How to typecast from var to an object
- C# Linq class searching - how to filter object collection
- How I could loop over an array of objects and add a property from each object to a variable using Linq?
- Using LINQ to loop through inner class properties in outer class collection
- C# How to loop through an array and find array with most recent date?
- How to run a LINQ query on a collection of objects and a collection inside of each object
More Query from same tag
- Using join on same table three times
- Return a list from Table-Valued SQL Function in LINQ?
- How to do condition statement in LINQ based on code variables?
- Nhibernate - partial loading of objects
- Lambda expression is slower than foreach statement?
- Why is Entity Framework ignoring the Take() method when generating SQL?
- Comparing two classes in LINQ - getting 'mismatches'
- Best way to map a parent-child list of objects
- Cannot exclude from a list items contained in another list with Linq
- Cleaning up a simple foreach with linq
- Linq to produce custom period in days, hours, minutes and seconds
- select all related objects
- Alternative to Linq Average method in C#
- How to Copy Common properties List<x> to List<y>
- Linq to Entities & SQL Server 2012: Insert consecutive number by a combination of fields
- LINQ: Error converting HashSet<Dictionary<String, String>> to Dictionary<String, HashSet<Dictionary<String, String>>>
- C# linq query with where subquery for each property
- Linq XML complex select (3 levels)
- Updating XML file in C#
- EF Core resursive model - order alphabetically on the same level
- When calling multiple join conditions getting Error
- Get all the direct Children of a specified Parent
- How to execute Linq query and Binding data in Lable of asp.net pages
- How to make a one to seven relationship, with only one of the seven types in each - Entity-Framework
- How to filter LINQ query by table column and get count
- Difference between Linq to Sql, Linq, Typed Datasets, ADO.NET
- How do I asynchronously enumerate a collection in an ASP.NET environment?
- Compare & Match Nested JSON Values
- Finding the distinct values of a dictionary
- Dynamic Linq with date fields