c# - LINQ to SQL execute method on select -
im new linq i'm trying figure out how execute method lambda expressions.
public void getdata() { using (myclassesdatacontext context = new myclassesdatacontext()) { var problems = (from p in context.problems select p).take(10); problems.select(t => displaydata(t.text)); } } public void displaydata(string text) { }
i'm getting error:
the type arguments method 'system.linq.enumerable.select(system.collections.generic.ienumerable, system.func)' cannot inferred usage. try specifying type arguments explicitly.
at line:
problems.select(t => displaydata(t.text));
what doing wrong?
select
operator used create projection - i.e. lambda expression passed argument instructs how create new object out of each object in collection.
what want is, instead, perform action on each item collection. use foreach
loop that:
var problems = (from p in context.problems select p).take(10); foreach (var t in problems) { displaydata(t.text); }
Comments
Post a Comment