lambda

How to write lambda methods in Objective-C ?

How to write lambda methods in Objective-C ? ...

How to reduce type declarations when using lambda parameters?

Below is a heavily cut down version of some code I have public class DataInfo<T> { public DataInfo(string description, Func<T, object> funcToGetValue) { this.description = description; this.funcToGetValue= funcToGetValue; } public readonly string description; public readonly Func<T, object> funcToGet...

If statement within Lambda function?

This may be quite simple but I'm rather new to Lambda's so bear with me. I have a function that uses a Lambda function to recurse. The main function receives a bool telling it to include certain information or not within the lambda. The function is designed to write out a custom class to XML - I think the code is pretty self explanitor...

Conditional LINQ where statement?

I have a linq statement that I want to add an additional where clause to if a drop down index is not 0. people.Where(n.surname == "surname" || n.forename == "forename" && (dropdown.SelectedIndex > 0) ? n.id = dropdown.SelectedValue : n.id > 0).Select(n => n); I am not even sure if what I am trying is possible?? I would like to do th...

Adding a random Guid column to a Linq to Entities query to grab random records

I've found some articles about using the RandomView view and the GetNewID function to pull back randomized records, but they are using this method with Linq to SQL which allows Functions and Stored Procs to be used with no return value or a scalar return value. From what I understand, a Stored Proc has to been returned as one of the Enti...

How do I filter a strongly typed list with List<String> variables

I need to filter a strongly typed list of type StaffingPositionsDataContract, with another list of filter names and values. I have these two lists: List<SerializedForm> deserializedObject = JsonConvert.DeserializeObject<List<SerializedForm>>(searchFilters).Where(x => !string.IsNullOrEmpty(x.value) && !string.Equals(x.value.ToUpper...

Howto create a System.Linq.Expressions.Expression for Like

I created a filterable BindingList from this source: http://www.nablasoft.com/alkampfer/index.php/2008/11/22/extend-bindinglist-with-filter-functionality/ It works great ( list.Filter("Customer == 'Name'"); does what it should. In the internals works a parser, that converts the expression "==" or "!=" into "System.Linq.Expressions.Exp...

Are the following Lambda and Linq expressions equivalent?

Hi Everyone, Are the following Lambda and Linq expressions equivalent in terms of execution paths? I guess I'm wondering if the Linq is going to run differently because it's going to create an IEnumerable before determining if the enumeration has anything in it whereas the lambda expression will stop on the first digit it finds. var x ...

Generic Linq ordering function?

I would like to be able to pass in a Func<T, ?> that allows me to choose exactly how to sort a list of items... the issue I have is the the return type might vary... so for example I want to do something like this (not production code): Func<POline, string> poLineOrder if (option) poLineOrder = poline => poline.PartNumber; else poLineO...

How to format lambda expressions and anonymous methods for maximum readibility?

For instance: Sorter.SortBy ( array, ( a, b ) => { return a > b; } ); What's the best way to format them for maximum readibility? Also think of it for one parameter lambda version, and other cases that might be used commonly. What are the guidelines? ...

Func without any parameters?

This may sound like a bit of a dumb question but how do I make a Func<> variable that doesn't return anything? ...

Where should Funcs/Actions/etc. go in code?

As the title says. Where do they go? they're variables, but they're also code... ...

Functors when should I use them whats their intended use.

I Just can't seem to wrap my head around them. As I understand it's dynamicly adding logic to a class. Are classes within the framework prepaired for this? Why should I just extend the class and add the funtionality to it in the extention. I would be globally accessable and afaik much easier to maintain. I've Read there are 4 functor ...

Struggling with VB .net Lambdas

I'm trying to use lambdas in some VB.Net code, essentially I'm trying to set a flag when databound is called. Simplified it looks like this: Dim dropdownlist As New DropDownList() dropdownlist.DataSource = New String() {"one", "two"} Dim databoundCalled As Boolean = False AddHandler dropdownlist.DataBound, Function(o, e) (databoundCall...

Captured variable instantiating problem

I'm currently musing about some idea I can't get right. The problem is that I want to use one lambda function to instantiate a captured variable and another lambda to access a property of that variable. Since the instantiating happens within the lambda the variable isn't actually instantiated the time I want to use it within the second...

How to use LINQ to compile a lambda expression to custom SQL or otherwise?

Starting with this code: int Count(Func<MyClass, bool> conditions) { // ... } And I want to call it like so: int c = Count(foo => foo.bar == 5 && !foo.blah); How do I then write the count function so that it ends up like so: int Count(Func<MyClass, bool> conditions) { // what goes here so that I get this: string sql = ...

Creating anobject passing a lambda expression to the constructor

I have an object with a number of properties. I want to be able to assign some of these properties when I call the constructor. The obvious solution is to either have a constructor that takes a parameter for each of the properties, but that's nasty when there are lots. Another solution would be to create overloads that each take a subs...

How can I get this dynamic WHERE statement in my LINQ-to-XML to work?

In this question Jon Skeet offered a very interesting solution to making a LINQ-to-XML statement dynamic, but my knowledge of lambdas and delegates is not yet advanced enough to implement it: I've got it this far, but of course I get the error "smartForm does not exist in the current context": private void LoadWithId(int id) { XDoc...

Lambda expression from C# to VB.Net

What would this line of C# using Lambda expression be in VB.Net? string s = blockRenderer.Capture(() => RenderPartialExtensions.RenderPartial(h, userControl, viewData)); Something with function of - but I can't figure out exactly how... ...

.NET / C# - Convert List to a SortedList

What is the best way to convert a List to SortedList? Any good way to do it without cycling through it? Any clever way to do it with an OrderBy()? WRAP UP Please read all answers and comments. ...