Taswar Bhatti
The synonyms of software simplicity
Tag: LINQ
linq

Here is a quick C# tip of counting up values of a Dictionary<TKey, TValue> where the values contains a List<T> using Linq. Lets say you have a Dictionary that contains Dictionary<string, List<Guid>> and you wish to find out how many items of Guid you have. You can easily do it by the Sum Linq aggregate […]

linq

Here is a LINQ tip where you may wish to order a collection with an existing ordering of another collection. Example:

Currently as it stands our data is stored in the order of { 5, 13, 7, 1, 8 } and we wish to order them in terms of { 1, 8, 5, 7, […]

linq

Recently I was asked a simple code to improve the performance, and at first I couldn’t see it but as you know your brain starts working when you aren’t thinking of the problem anymore. (It happen to me when I was driving) Anyway the problem on hand was there is a for loop and when […]

linq

Was going through some legacy code recently and found a big for loop that had multiple switch statement inside. So being that I hate something that is fairly large, every method should be small and concise, I went along to refactor it to SRP. This code is generic so you might see something like this […]

linq

Here is some poorly written code that I had to review today and modify (i.e refactor). I have removed the domain of the code and renamed the variables, so that it remains anonymous, but the just of the code is still intact.

Lets go through the inner loop of the code first. First the […]

linq

So sometimes you will get these strange errors or exceptions when using Linq Sequence contains no matching element For example if you use

This will throw InvalidOperationException with Sequence contains no matching element. But if you use

Which will return you a null if its not found then you can check if the […]

Working Effectively with Legacy Code

In this Learn Series I am going to write about the Sprout Method which is in the book “Working Effectively with Legacy Code by Michael Feathers“, all I have to say is what a great book if you don’t have it, you should pick it up asap. Sprout Method is a technique that one can […]

UA-4524639-2