101 LINQ Samples 2

OK, I’ve just discovered this. If, like me, you’re always struggling to remember the name of that LINQ extension method, or precisely how it’s supposed to work, then this is really useful. http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx Every single LINQ extension method, categorized, and all on one page without all the method overload signatures that just end up confusing you. Then, once you’ve identified the one you need a single click will take you to a concise yet precise example of how to use it, and what result you can expect. Simply brilliant! I’ve no idea who did this, but thank you.

Feature Jealousy

What’s got LINQ, but doesn’t have a yield keyword and no Action or multiline lambdas? What’s supposed to be an easy to learn language, but supports exception filters when other supposedly more complex languages don’t? The answer, VB.NET. “Co-evolution” has been announced for VB.NET 10.0 and C# 4.0. However, VB.NET doesn’t appear to be getting yield, and C# won’t be getting XML literals (which I personally think is a good thing). I think VB.NET shed the “Beginners” bit from BASIC a long time ago. What do you think? Oh, and whilst I’m at it, who’s up for an __il keyword in C# so you can have inline blocks of IL?

Flexible Enumerations 7

Sometimes enumerations in .NET just don’t cut it. In the end they’re just a numeric value to which a piece of string metadata is attached to some of the values. Consider the following enumerations: public enum OfficeLocationNames { London, Edinburgh, Redmond } public enum OfficeLocationCodes { LON, EDI, RED } What are these enumerations actually trying to say? I see these and think that there are three office locations, London, Edinburgh and Redmond, and each has a name and a three letter code, i.e. one type of thing, an office location, with two pieces of descriptive information about that thing, name and code. But using enumerations has forced us to define two things, when it’s really one. So what solutions are there? Here’s one solution I like. I’m sure there are more, so feel free to suggest variations or completely different patterns in the comments. First off I define an ...

LINQ is amazing!

I’m just starting to get my head around what LINQ is all about, and I have to say I love it! What’s really struck me is the power of LINQ to Objects to concisely and accurately describe the intention of the code without the usual complexity of loops and ifs. To give you a example, I’m putting together a simple proof of concept publish/subscribe message bus in .NET at the moment. It’s at the very early stages at the moment, and I’m sure it’ll be the subject of future posts, but one of the first things I needed to do is match a published message to a set of subscriptions to identify the subscribers to activate. The original version of the code involved a foreach loop and a number of if conditions to find the correct subscriptions for the published message. It worked just fine, and read fairly well too. ...