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.


Related Query

More Query from same tag