Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Thinking in LINQ
Mike Taulty's Blog

Mike's Badges

Follow on Twitter
View mike's profile on slideshare
Add to Technorati Favorites
CW Blog Awards

For the first time, I'm writing bits of code that are nothing to do with LINQ but I'm using the V3.0 C# compiler and so I'm starting to think "Hey, I could use a bit of LINQ" here.

Just a moment ago, I wanted to find any network interface that had an available IPV6 address. It took me a little while to write;

 

     UnicastIPAddressInformation ipAddressInfo =
            (
              from ni in NetworkInterface.GetAllNetworkInterfaces()
              from ad in ni.GetIPProperties().UnicastAddresses
              where ni.OperationalStatus == OperationalStatus.Up
                && ad.Address.AddressFamily == AddressFamily.InterNetworkV6 
              select ad
            ).First();

Now, I'm not sure at this point that it actually works - Mike's first Law of Software states;

Single Step The Code in a Debugger whilst Applying a Mindset of "How Many Places Can I Make This Fail?".

so there's something in there about LINQ in that, in these early days, it's easy to formulate a query that's neat and highly readable (and so maintainable) but it's also not so easy (for me) to be confident yet that I've actually written the right thing. Maybe that'll get easier over time after I've single-stepped a few of these things and seen the right results pop out.


Posted Fri, May 18 2007 2:16 AM by mtaulty

Comments

Christopher Steen wrote Link Listing - May 18, 2007
on Fri, May 18 2007 8:05 PM
WCF Addressing In-Depth [Via: Aaron Skonnard ] Demo code for Mix07 talk: Silverlight: Creating and Delivering...
(C) Mike Taulty, 2009. All rights reserved. The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems