lambda

Sorting a list using Lambda/Linq to objects

I have the name of the "sort by property" in a string. I will need to use Lambda/Linq to sort the list of objects. Ex: public class Employee { public string FirstName {set; get;} public string LastName {set; get;} public DateTime DOB {set; get;} } public void Sort(ref List<Employee> list, string sortBy, string sortDirection) { ...

VS debugging "quick watch" tool and lambda expressions

Why I can’t use lambda expressions while debugging in “Quick watch” window? ...

C# 3.0 - How can I order a list by week name starting on monday?

Hi! I have a list of events and each of them has a weekday registered. And now I'm trying to show all of these events, but ordered by the weekday name (monday, tuesday, wednesday...). How can I do this? I'm using LinqToSQL and Lambda Expressions. Thanks!! ...

Anonymous delegates in vb.net (pre vb9)?

Is it possible to create anonymous delegates in vb.net version 8 or earlier? If so, could someone provide an example of the syntax? Thanks. ...

Dynamically creating a menu in Tkinter. (lambda expressions?)

I have a menubutton, which when clicked should display a menu containing a specific sequence of strings. Exactly what strings are in that sequence, we do not know until runtime, so the menu that pops up must be generated at that moment. Here's what I have: class para_frame(Frame): def __init__(self, para=None, *args, **kwargs): ...

Generic constraint to ValueTypes, Strings and Nullable of ValueTypes

I'm trying to add a constraint to a generic method so it checks for ValueTypes, Strings or Nullable value types. The problem is that: value types are struts strings are immutable reference types nullable are value types but won't be accepted in a "where S : struct" type constraint. So does anybody know if there's a way I can accep...

How to cast Expression<Func<T, DateTime>> to Expression<Func<T, object>>

Hi guys, I've been searching but I can't find how to cast from the type Expression<Func<T, DateTime>> to the type: Expression<Func<T, object>> So I must turn again to the SO vast knowledge ;) ...

Dictionaries and Lambdas fun

Why would this compile: public Dictionary<ValueLineType, Func<HtmlHelper, string, object, Type, string>> constructor = new Dictionary<ValueLineType, Func<HtmlHelper, ...

How to convert Func<T, bool> to Predicate<T>?

Yes I've seen this but I couldn't find the answer to my specific question. Given a lambda testLambda that takes T and returns a boolean (I can make it either Predicate or Func that's up to me) I need to be able to use both List.FindIndex(testLambda) (takes a Predicate) and List.Where(testLambda) (takes a Func). Any ideas how to do b...

ThreadPool.QueueUserWorkItem with a lambda expression and anonymous method.

Passing two parameters to a new thread on the threadpool can sometimes be complicated, but it appears that with lambda expressions and anonymous methods, I can do this: public class TestClass { public void DoWork(string s1, string s2) { Console.WriteLine(s1); Console.WriteLine(s2); } } try { TestClass te...

Passing a method to another method

Is it somehow possible to send a function to another function for it to run. For instance...I want to have an attribute on a field where I can specify a method that will be sent to another method where the method passed in will be run. Not sure if that makes any sense but here's a small example. [ValidateIf(x=>x.test())] public string ...

In explicit LINQ-to-SQL (C#) does order matter?

Hi, I know Linq-to-SQL is dead, but anyway, I think this is really basic, I'm just confused about what magic Linq-to-SQL does and doesn't do with regards to the SQL it generates. If I have built up an Expression tree as "myPredicate", and have something like this: (from request in DataContext.RequestsTable select request).Where(myPredi...

Turn very simple Expression<Func<T, bool>> into SQL where clause

I have a number of different data sources that I need to query and have been able to do confine all my queries to very simple expressions with no more than 2 conditions. An example of typical complexity of my lamba Expressions is: b => b.user == "joe" && b.domain == "bloggs.com" On my non-SQL data sources I'm ok as I can convert them ...

How do I search the collection of a collection in my LINQ Where clause?

I've got the following ADO.NET Entity Framework Entity Data Model: I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status. This LINQ Does Not Work: Dim ServicesId As Integer = ... Dim KeywordStatus As Integer = ... Dim FoundPolicyholders = From p As Policyholder In db.Policyholde...

How can I get this example using "param" in C# to work?

I am trying to understand the meaning and use of the param parameter in this line taken from a RelayCommand example: return new RelayCommand(param => MessageBox.Show("It worked.")); First, I understand that the "param" parameter has nothing to do with the "params" keyword, is this correct? public int Add(params int[] list) { int su...

Combining multiple lambda functions together with efficient execution

I'm trying to create a dynamic filter using a combination of lambda functions. But the number of lambda functions could vary based on the number of different filters the user applies. I want something that behaves like this //images is a List<ImageInfo> var result1 = images .Where(image => image.Bytes < 1000) .Where(image => image.Hei...

How to get this working example example of delegates to pass lambda syntax as a parameter?

I'm trying to make my own understandable example of what the method RelayCommand is doing in the following code: return new RelayCommand(p => MessageBox.Show("It worked.")); the constructor is this: public RelayCommand(Action<object> execute, Predicate<object> canExecute) { if (execute == null) throw new ArgumentNullExcep...

lambda expression to verify list is correctly ordered

I want to write a lambda expression to verify that a list is ordered correctly. I have a List where a person has a Name property eg: IList<Person> people = new List<Person>(); people.Add(new Person(){ Name = "Alan"}); people.Add(new Person(){ Name = "Bob"}); people.Add(new Person(){ Name = "Chris"}); I'm trying to test that the list i...

Creating anonymous types based on lambda expression

Hi, I'm trying to create a Fluent Interface to the Winforms Datagrid. This should allow me to use a typed datasource and easy use of properties of properties (Order.Custom.FullName) I'm adding the columns on initialization and trying to set the property to use there: dgv.With<Order>().Column("Client Name").On(x => x.Client.FullName); ...

Do we need fixed point combinators in C#?

I was playing with recursive lambdas in C# and have found two approaches to do this on the web. One approach uses fixed point combinator and the other does not. In the code below f1 is built using combinator, and f2 is defined directly. My question is, do we need fixed point combinators in C# or the language already provides all we need,...