15
votes
3answers
444 views

Lambda Scope Clarification

Why does my parameter x behave so erratically? Example 1 - Doesn't exist in the current context. Example 2 - Cannot reuse x because it's defined in a 'child' scope. Example 3 - Fine. This is the ...
13
votes
10answers
10k views

Beginner book for Lambda Expression [closed]

I'm a beginner in lambda, I would like to know your suggestion for the best tutorial ebook/video on using lambda expression. Thank you
10
votes
2answers
148 views

How to cast lambdas?

I'd like a family of functions to be kept in a dictionary that derive from some base type (lets call the base class "object" for example sake). So, it it possible to keep f1 in f2? Func<bool> ...
7
votes
2answers
2k views

How to return value with anonymous method?

This fails string temp = () => {return "test";}; with the error Cannot convert lambda expression to type 'string' because it is not a delegate type What does the error mean and how can I ...
5
votes
4answers
219 views

linq ambiguity on where and select

Today I ran into an issue with LINQ to objects (not SQL) that popped up due to a typo. I had a .Select one place and a .Where in another place. I was expecting same result but they are showing ...
5
votes
4answers
2k views

How to get last x records from a list with Lamdba

I have as List of strings with where i remove each duplicates, now I want to filter it even more to get the last 5 records. How can I do this? What I got so far List<string> query = ...
5
votes
2answers
2k views

How to “let” in lambda expression?

How can I rewrite this linq query to Entity on with lambda expression? I want to use let keyword or an equivalent in my lambda expression. var results = from store in Stores let ...
5
votes
4answers
304 views

Lambda expression “IN” operator Exists?

I'm looking for to build the Lambda expression like the below IQueryable<Object> queryEntity = _db.Projects.Where(Project=>Project.Id.IN(1,2,3,4)); I don't find any IN ...
5
votes
1answer
241 views

Creating a Func<> dynamically - Lambdas vs. Expression trees

Here is some code to return a linear function (y=ax+b). public static Func<double, double> LinearFunc(double slope, double offset) { return d => d * slope + offset; } I could do the ...
5
votes
1answer
4k views

Lambda expressions - set the value of one property in a collection of objects based on the value of another property in the collection

I'm new to lambda expressions and looking to leverage the syntax to set the value of one property in a collection based on another value in a collection Typically I would do a loop: class Item { ...
4
votes
4answers
143 views

General Lambda syntax question

So I seem to be confident that the following 2 statements are the same List<object> values = new List<object>(); values.ForEach(value => ...
4
votes
3answers
7k views

Equivalent of SQL Between Statement Using Linq or a Lambda expression

Don't think this is a repost, difficult to search for the word between because it is used in everything (like searching for AND). I want to filter a list based on a date range. I have a list with ...
4
votes
3answers
87 views

Why are lambdas convertible to expressions but method groups are not?

LINQPad example: void Main() { One(i => PrintInteger(i)); One(PrintInteger); Two(i => PrintInteger(i)); // Two(PrintInteger); - won't compile } static void ...
4
votes
1answer
1k views

Join 3 tables with a lambda expression?

I basically want the following sql query as a lambda expression: SELECT studentname, coursename, grade FROM student S, course C, grade G WHERE S.id = G.studentid AND C.coursecode = G.coursecode AND ...
4
votes
2answers
358 views

Why doesn't HasFlag() work in Linq to Entities?

I have a flag e.g. [Flags] public enum DaysOfTheWeek { Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8, Friday = 16, Saturday = 32, Sunday = 64 } If I want to use ...

1 2 3 4 5 9
15 30 50 per page