Why LINQ is Better than ForEach

I had a discussion today with a software architect who disagreed with me that LINQ to Objects should be used instead of foreach loops. My claim is that LINQ is better. He says that I shouldn’t make such a blanket statement, because LINQ is inefficient. I stand by my assertion. Declarative Code is Easier to [...]

Share

Tags: , ,

Read Users' Comments (0)

How to Use .Except with EqualityComparer

Today we’re going to cover an advanced scenario where we need to compare lists of a class we created. We’ll start with an implementation of EqualityComparer<T> which consists of overriding two methods: Equals and GetHashCode. What was a little tricky about this implementation is this subtle, but critical, comment in the code sample on MSDN [...]

Share

Tags: , , , , , ,

Read Users' Comments (1)

Solving Issues With LINQ Foreach Variables

Can you guess what the output of the following program is? using System; using System.Collections.Generic; namespace Lambda { class Program { static void Main(string[] args) { var strings = new[] {“a”, “b”, “c”}; var actions = CreateActions(strings); actions.ForEach(f => f()); } private static List CreateActions(IEnumerable strings) { var actions = new List(); foreach (var s [...]

Share

Tags: ,

Read Users' Comments (0)