Tag Archives: Action

Another removing Lambda “trick”

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, [...]

Leave a comment Continue Reading →

The Switch Remover: Convert Switch Statements to Dictionaries

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) { [...]

Leave a comment Continue Reading →

Solve FizzBuzz Using Linq Extension Methods

So if you haven’t heard of the FizzBuzz test, it’s basically taking in a list of numbers and figuring out if they are divisible, cleanly, by two numbers. Say you have 3 and 5 and this is your list: 1 3 5 10 15 If the number is divisible by 3, then return the Fizz [...]

Leave a comment Continue Reading →

Life is fun when you are slow

public void IfTrueRunMethod(Func<Boolean> trueMethod, Action action) { if(trueMethod()) { action(); } } Just something I made for the hell of it to remove: if(someClass != null && someClass.Property == “hi”) { SomeMethod(); } This can be reduced to one line… yay! IfTrueRunMethod(() => { someClass != null && someClass.Property == “hi” }, () => SomeMethod()); [...]

Leave a comment Continue Reading →

IEnumerable Extention Methods and Action

This may be slightly off, but I’ve pretty much figured them out and how they work with lambda expressions. First off, Lambda expressions. These are the odd looking currentItem => expressions you might see in my examples. They are a little misleading, at least to me they were. When I saw: ilist.SomeExtension(currentItem => SomeMethod(currentItem)); I [...]

Leave a comment Continue Reading →