The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,184 other subscribers

Archive for April 2nd, 2013

.NET/C# – Some notes in IGrouping (via: Grouping in LINQ is weird (IGrouping is your friend) – Mike Taulty’s Blog)

Posted by jpluimers on 2013/04/02

IGrouping interface diagram (click to enlarge)

IGrouping interface diagram (click to enlarge)

One of the things most people find hard to use in LINQ is GroupBy or the LINQ expression group … by (they are mostly equivalent).

When starting to use that, I was also confused, mainly because of two reasons:

  1. GroupBy returns a IGrouping<TKey, TElement> generic interface, but the classes that implement it are internal and not visble from outside the BCL (although you could artificially create your own).
    This interface extends the IEnumerable<TElement> in a full “is a” fashion adding a Key member.
    This has two consequences:

    1. Because it is a “is a” extension of the IEnumerable<TElement>, you can use foreach to enumerate the TElement members for the current group inside the grouping.
      No need to search for a Value that has the Elements, as the Group is the Elements.
    2. The Key member is indeed the current instance of what you are grouping over. Which means that Count<TElement>, are for the current group in the grouping.
  2. The LINQ expression syntax for grouping on multiple columns is not straightforward:
    1. Grouping on multiple columns uses a bit different syntax than you are used from SQL.
      (Another difference is that SQL returns a set, but groups are IEnumerable)
    2. You also need to be a bit careful to make sure the group keys are indeed distinct.

Most people don’t see the IGrouping<TKey, TElement> because they use the var keyword to implicitly the LINQ result.
Often – when using any anonymous type – var is the only way of using that result.
That is fine, but has the consequence that it hides the actual type, which – when not anonymous – is a good way of seeing what happens behind the scenes.

David Klein gave an example for the multi column grouping and also shows that if you use LINQPad, you can actually see the IGrouping<TKey, TElement> in action.

Mike Taulty skipped the Group By Syntax for Grouping on Multiple Columns in his Grouping in LINQ is weird (IGrouping is your friend). So my examples include that.

Note that I don’t cover all the LINQ group by stuff, here, for instance, I skipped the into part.
There are some nice examples on MSDN covering exactly that both using Method based and Expression based LINQ.

The examples are based on these two classes, similar to what Mike did. Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development | Leave a Comment »

So you thought Google TiSP (Toilet Internet Service Provider) was an April 1st joke? Not in The Netherlands…

Posted by jpluimers on 2013/04/02

If you thought the 2007 Welcome to Google TiSP (Toilet Internet Service Provider) and the Google TiSP ACTUAL Installation – YouTube formed a great April 1st joke, then you have miscounted the futurists.

Found out a while ago, that in The Netherlands, a variation of TiSP was used to provide internet through the sewage system:

  1. July 18th, 2012, in the province Friesland, a glas fiber cable was put through the sewer system:
    Frisian: Glêsfezelkabel troch rioel | Omrop Fryslân – Alle dagen nij!.
    Dutch: Glasvezelkabel door riool | Omrop Fryslân – Alle dagen nij!.
  2. Late 2012, plans were revealed to connect a few farms to glassfiber using the sewing system in early 2013:
    Twents dorp krijgt glasvezel via het riool | IT Pro | Tweakers.

The Belgians and Germans seem to favour the water pipes over the sewer though:

–jeroen

Posted in Internet, Power User | Leave a Comment »

 
%d bloggers like this: