Tag Archive - Lambda

Linq Join Extension Method and How to Use It…

29 April 2009 by Sean, 3 Comments

I don’t like using the query syntax when it comes to Linq to AnythingButTheKitchenSink . Not sure why. Mostly, I guess, is that I seem to have a liking for Funcs and Actions to the point of stupidity and although you can work them into the query syntax, it just doesn’t look right. Now with [...]

Tags: , ,

Linq Extension Methods Versus Linq Query Language… DEATHMATCH

13 November 2008 by Sean, No Comments

Today I was writing out an example of why the extension methods are for the most part better to use than the querying language. Go figure I would find a case where that’s not entirely true. Say you are using these three funcs: Func<User, String> userName = user => user.UserName; Func<User, Boolean> userIDOverTen = user [...]

Tags: , , , ,

Cannot Resolve Method, Can’t Infer Return Type, and Funcs

6 November 2008 by Sean, No Comments

So ran into this today and the answer was actually a lot easier to understand than I thought it would be. Say you want to order a list of objects by a number. Seems simple. Now if you have been paying attention you would know I like using Funcs. Func<SomeClass, Int32> orderByNumber = currentClass => [...]

Another removing Lambda “trick”

3 November 2008 by Sean, No Comments

And by trick, I mean I was too slow to realize that: someDictionary.Add(“Hi”, (Boolean doThis) => SomeMethod(doThis)); Can be done this way: someDictionary.Add(“Hi”, SomeMethod); Where the dictionary is: Dictionary<String, Action<Bool>> someDictionary; someDictionary = new Dictionary<String, Action<Bool>>(); And SomeMethod is: void SomeMethod(Boolean doSomething) { //Something is to be done! } Which as far as I know, [...]

The Switch Remover: Convert Switch Statements to Dictionaries

17 October 2008 by Sean, No Comments

Folks, what if I told you that Switch is a thing of the past? What if I told you I had a way to reduce code in certain areas so that you don’t have that messy Switch logic? What would you pay for that? Would you pay $19.95? Not convinced? Well take this: switch(someDropDownList.SelectedValue) { [...]

Uhg It Won’t End

10 October 2008 by Sean, No Comments

Still on the readability thing, but there was a second argument in the post that inspired now what is three posts of my own here. The question was should you use Linq based on people saying it’s more readable, therefore just making it syntax sugar. foreach(Item current in itemList) { itemNameList.Add(current.Name); } Versus var itemNameList [...]

What Is Readable Addon

10 October 2008 by Sean, No Comments

Quick thought too about which to use due to readability: var you = from factor in seansAwesomeness select new FactorLite { Amount = amount; }; or you could do: Func<Person, FactorLite> selectFactorLite = currentFactor => new FactorLite { Amount = currentFactor.Amount }; seansAwesomeness.Select(selectFactorLite); I guess it’s a matter of preference, but the first seems way [...]

Tags: , , ,

What Is Readable

10 October 2008 by Sean, No Comments

So a couple of posts I read recently have been about readability of Linq, more so Linq query expressions versus the Linq methods. Don’t know what I mean? Expression: var result = from knowledge in Sean select knowledge.Linq; As opposed to: var result = Sean.Select(knowledge => knowledge.Linq); Personally I would replace the lambda expression with [...]

More Fun With Linq

30 September 2008 by Sean, No Comments

Say you have a class named BannedProgram and it has a collection of DayOfWeek and a string ProcessName. Now the collection of DayOfWeek is basically a way to set the days of the week it’s banned. With this you want to create a collection of these BannedPrograms, each with their own names and days they [...]

Tags: , ,

Combine Lambda Expressions: The And and the Or

9 September 2008 by Sean, No Comments

Found this post here but wanted to make a really simple example to demonstrate this. The idea is simple, take something like this: currentItem => currentItem.BooleanMethodOne() && currentItem.BooleanMethodTwo() but say you only want to have one clause or both. Well you could make three separate expressions, but what if you wanted to add even more [...]