Posted
on May 10, 2011
by
[ICR]
under
C#
Quite a lot of times it seems these little extension methods come in handy. They give the maximum or minimum value(s) from an IEnumerable, optionally applying a projection for the ordering. They have better complexity characteristics than ordering and taking the first item, which requires time and space to order pairs of items that we [...]
Posted
on December 12, 2009
by
[ICR]
under
C#
It’s fairly common to see something like the following code: bool allEmpty = stringList.Any(s => String.IsNullOrWhiteSpace(s)); When all that is needed is: bool allEmpty = stringList.Any(String.IsNullOrWhiteSpace); Enumerable.Any takes a function which takes a string argument. String.IsNullOrWhiteSpace is a function which takes a string argument (as is s => String.IsNullOrWiteSpace(s)) and so can be passed to [...]
I was reading about permutation algorithms to try and solve a completely unrelated problem when I came across this. It’s an algorithm to generate a random subset of size s from n elements. I’ve needed something like this in the past, and so no doubt I’ll need something like it again in the future. private [...]