Browse by Tags
All Tags »
Tools: Linq Extensions (
RSS)
Here we go with the third installment of the Extension Method Roundup. The reason behind these 'code dumps' is that LINQ is a central part of my coding and always find new problems I want to find elegant solutions to. Hope these prove as useful to you as they do to me. Intersect / Union Again...
As a rule of thumb, when presented with two independent blocking I/O operations on more than one independent devices, it's best to use threads to create parallel operations, instead of waiting for a single synchronous operation to complete. That way, executing operations O 1 , ..., O n , each of...
Hey hey hey! It's time for another Extension Methods Roundup! Here are some of the extension methods I've written since the last one: Dictionary's Missing Remove Methods public static void Remove<TKey, TValue>( this IDictionary <TKey, TValue> dictionary, TValue value) { // Check...
As I do from time to time, here is a batch of three Extension Methods I've written recently: IndicesWhere /// <summary> /// Gets the indices where the predicate is true. /// </summary> public static IEnumerable < int > IndicesWhere<T>( this IEnumerable <T> enumeration...
Sometimes you want to use FirstOrDefault , but the default value of T is a valid value that might get returned. If you used FirstOrDefault , you wouldn't know whether the value that you got is a valid first or the default fallback. I use FirstOrFallback to explicitly specify which fallback value...
I've updated my long standing Linq Extensions project on CodePlex to .NET 3.5 RTM and added the latest extension methods. You can open bugs and feature requests using the Issue Tracker . If you want to download it, go and download the source code directly . [Cross-Posted from Omer van Kloeten's...
Enumerating over a Dictionary<TKey, TValue> you will get structs of type KeyValuePair<TKey, TValue> . Whenever you use the ToDictionary extension method, you are forced to specify how to get the key and value for each item, even if it's an enumeration of KeyValuePair s. Seems a bit redundant...
Here's another Linq method I wanted to share. This one takes two enumerations, enumeration and subset and checks to see whether subset exists in enumeration in its original order. I used the naming convention set by SequenceEqual . Examples: enumeration = (1, 2, 3, 4, 5); subset = (3, 4) ==> SequenceSuperset...
I've created a couple of useful extension methods that I like to use with Linq, so here they are: ContainsAtLeast I've noticed that there's no way to find out whether a collection has at least X items. The following takes the collection, tries to take X items from it and asks whether it succeeded...