lambda

What is wrong with my custom thread pool?

I've created a custom thread pool utility, but there seems to be a problem that I cannot find. using System; using System.Collections; using System.Collections.Generic; using System.Threading; namespace iWallpaper.S3Uploader { public class QueueManager<T> { private readonly Queue queue = Queue.Synchronized(new Queue()); private...

Is it possible to cast a delegate instance into a Lambda expression?

Here the context for my question: A common technique is to declare the parameter of a method as a Lambda expression rather than a delegate. This is so that the method can examine the expression to do interesting things like find out the names of method calls in the body of the delegate instance. Problem is that you lose some of the int...

What is the best way to ReadLine by Expression Tree?

If I want to get a user input from Console to my Expression Tree. What is the best way to do it? and how to make variable 'name' duck typing? Here are my code. using System; using System.Reflection; using System.Collections.Generic; using Microsoft.Linq; using Microsoft.Linq.Expressions; namespace ExpressionTree { class Program ...

Which article/blog on the web really helped you to get started with Lambda Expression concepts?

Any resources which explain the lambda expression concepts simply. ...

Lambda expressions support in VS2008 SP1

Is there support for lambda expressions from C++ 0x in Visual Studio 2008 SP1? Example below throws me syntax errors. Is there any '-Cpp0x' flag for compiler or something? #include <algorithm> #include <iostream> #include <ostream> #include <vector> using namespace std; int main() { vector<int> v; for (int i = 0; i < 10; ++i) ...

Patterns or techniques for designing a flexible advanced search with Linq Expression Trees

I'm looking to add an "advanced search" capability to my ASP.NET/SQL Server 2005 application. Ideally, I'd like it to be table driven. For example, if my schema changes with the addition of a new column to a table that I want to search, I'd like to have the UI reflect the addition of the new column as a searchable field. I can envisio...

Empty while loop with linq/lamba expression

Where I work we're still on .Net 2.0, but I'm somewhat familiar with the 3.0/3.5 stuff. I wanted to get some practice using linq/lambda expression in C# so I wrote a simple Sudoku solver using a lot of generic List<T> and lambda expressions with the aggregate methods it provides. In my solver, I have this at the top of the solver algor...

Can a lambda function call itself recursively in Python?

A regular function can contain a call to itself in its definition, no problem. I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no name to refer back to. Is there a way to do it? How? ...

Using LINQ2Sql for Validate Users

Hi there im using Linq for check if two user fields correspond for an unique user register in SQL Table, for example UID : userID PIN : passID so fields have to be from a single user, i was trying this: public bool AutentificacionUsuario(string userID , string password passID) { USER _userID = _db.USER.FirstOrDefault(uid ...

What's the deal with this Lambda?

Dim count As Func(Of Integer, Boolean) = Function(x As Integer) x = 1 If (count(GetSelectedCount())) Then 'Proceed Else MessageBox.Show("You can only select one item at a time.", "Multiple items selected", MessageBoxButtons.OK) End If GetSelectedCount returns the number of items checkemarked in a grid. ...

Convert existing snippet of code to use Array.ForEach

We know that if you have: var aa = new [] { 1, 2, 3, 4, 5 }; for (int i = 0; i < aa.length; ++i) { aa[i] = aa[i] + 1; } it's really var aa = new [] { 1, 2, 3, 4, 5 }; Arrary.ForEach(aa, a => a + 1); However, what if I had this: var aa = new [] { 1, 2, 3, 4, 5 }; var ab = new [] { 1, 2, 3, 4, 5 }; for (int i = 0; i < aa.length;...

Concatenating Lambda Functions in C#

Using C# 3.5 I wanted to build up a predicate to send to a where clause piece by piece. I have created a very simple Console Application to illustrate the solution that I arrived at. This works perfectly. Absolutely perfectly. But I have NO idea how or why. public static Func<Tran, bool> GetPredicate() { Func<Tran, bo...

C# 3.0: Need to return duplicates from a List<>

I have a List<> of objects in C# and I need a way to return those objects that are considered duplicates within the list. I do not need the Distinct resultset, I need a list of those items that I will be deleting from my repository. For the sake of this example, lets say I have a list of "Car" types and I need to know which of these ca...

Best resource for learning LAMBDA expressions

What are the best resources to learn LAMBDA expressions? They still have me a bit confused and I don't use them much. Also LINQ has me a bit confused, since both things are more or less in the same boat, maybe you guys can offer some good LINQ resources too. ...

How do you create python methods(signature and content) in code?

I've created a method that generates a new class and adds some methods into the class, but there is a strange bug, and I'm not sure what's happening: def make_image_form(image_fields): ''' Takes a list of image_fields to generate images ''' images = SortedDict() for image_name in image_fields: images[image_name] = fo...

select child object collection with lambdas

I have the following class objects: public class VacancyCategory { public int ID { get; set; } public string Text { get; set; } public IList<VacancySubCategory> SubCategories { get; set; } } public class VacancySubCategory { public int ID { get; set; } public string Text { get; set; } public VacancyCateg...

Can I ignore delegate parameters with lambda syntax?

I am curious why C# allows me to ignore delegate parameters in some cases but not others. For instance this is permitted: Action<int> action = delegate { Console.WriteLine("delegate"); }; but this is not: Action<int> action = () => Console.WriteLine("lambda"); Is there a way to initialize a delegate and ignore the parameters using...

Access 2003 - Field from another database on form

I am 'fixing up' an old Access Database, and the client requested that a DATE field be added to a form. Problem is, I have NEVER used Access before. I'm a SQL guy, and I build my own UI's. This forms thing is getting the better of me. Ok - So I have two tables: tblQuestionairre QuestionairreID EventID blah blah blah tblEvent EventID D...

How can I get rid of this smell? (refactoring switch statement)

Yesterday i was playing with jQGrid plugin and ASP.NET. Everything turned out well, my grid is working now, but i have two methods, that make my code smell. smelly methods: private IOrderedEnumerable<Employee> GetOrderedEmployees(Column sortColumn, bool ascending) { switch (sortColumn) { case Column.Nam...

C# lambda - curry usecases

I read This article and i found it interesting. To sum it up for those who don't want to read the entire post. The author implements a higher order function named Curry like this (refactored by me without his internal class): public static Func<T1, Func<T2, TResult>> Curry<T1, T2, TResult>(this Func<T1, T2, TResult> fn) ...