Archive

Posts Tagged ‘linq’

101 LINQ Samples

January 14th, 2011 No comments

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.

Tags: ,

Feature Jealousy

March 25th, 2009 No comments

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?

Tags: , ,

LINQ is amazing!

May 21st, 2008 No comments

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. But just I think the LINQ version speaks for itself:

var subscriptionsToActivate = from subcriptionObject in subscriptions
           where subcriptionObject is Subscription<T>
           let subscription = (Subscription<T>)subcriptionObject
           where subscription.ShouldActivateFor(message)
           select subscription;

Nuff said!

Tags: ,