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 1,470 other followers

Archive for the ‘LINQ’ Category

LINQ Debugging and Visualization – Simple Talk

Posted by jpluimers on 2017/12/12

LINQ is certainly extraordinarily useful. It brings the power of query expressions to C#, allowing an easy way of getting the data you need from a variety of data sources. Up to now, there hasn’t been a VS debugger for LINQ that gives you the means to visualise the data at every point in the chain. Michael Sorens, a keen LINQ user, describes a third-party tool that now promises to make using LINQ something we can all participate in.…

Great read. [WayBackLINQ Debugging and Visualization – Simple Talk

Via: [WayBackLINQ Debugging and Visualisation – Jeroen Wiert Pluimers – Google+

–jeroen

Posted in .NET, Development, LINQ, Software Development | Leave a Comment »

.NET/C#: Igor Ostrovsky wrote a few great MSDN magazine articles helping you write better threading code

Posted by jpluimers on 2013/09/17

Igor Ostrovsky wrote a few very nice MSDN magazine articles. Not all of them have ended up in the list at MSDN magazine, so here is a more complete list:

Though the articles show the majority of sample code in C#, the actual topics are of great interest to any developer writing .NET code or interfacing to it.

Some keywords in his articles: Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET CF, C, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, F#, LINQ, PLINQ, Prism, Software Development, VB.NET, VB.NET 10.0, VB.NET 11.0, VB.NET 7.0, VB.NET 7.1, VB.NET 8.0, VB.NET 9.0 | Leave a Comment »

c# – What’s the hardest or most misunderstood aspect of LINQ? – Stack Overflow

Posted by jpluimers on 2013/05/07

It is such a pity that StackOverflow is not the place any more for questions like these:

c# – What’s the hardest or most misunderstood aspect of LINQ? – Stack Overflow.

These questions and answers historically got me most of the insight from SO.

Alas, no more.

–jeroen

Posted in .NET, Development, LINQ, Opinions, Pingback, Software Development, Stackoverflow | Leave a Comment »

.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 »

.NET/C# LINQ gem: How to check if a char in a list of characters (via Stack Overflow)

Posted by jpluimers on 2012/11/21

Often when comparing characters with a list of characters, that list does not consist of consts.

It if were, you could make a switch statement:

                    switch (item)
                    {
                        case '/':
                        case '\\':
                        case ';':
                            addSeparator(separatorsUsed, item);
                            break;
                    }

But reality is that you cannot do things like this:

                    switch (item)
                    {
                        case Path.AltDirectorySeparatorChar: // Error: A constant value is expected
                        case Path.DirectorySeparatorChar:
                        case Path.PathSeparator:
                            addSeparator(separatorsUsed, item);
                            break;
                    }

However, you can perform a small trick and use LINQ to write some pretty elegant code based on Contains.

                    char[] pathSeparators = { Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar, Path.PathSeparator };
                    // LINQ: http://stackoverflow.com/questions/1818611/how-to-check-if-a-char-in-a-char-array/1818635#1818635
                    if (pathSeparators.Contains(item))
                        addSeparator(separatorsUsed, item);

The LINQ logic has the logic backwards (you can think of it like “item in pathSeparators”, but it is far easier to read than this:

                    if ((item == Path.AltDirectorySeparatorChar) || (item == Path.DirectorySeparatorChar) || (item == Path.PathSeparator))
                        addSeparator(separatoseparatorsUsedrsInUse, item);

Full source of a demo application: Read the rest of this entry »

Posted in .NET, .NET 3.5, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development, Visual Studio 11, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | 2 Comments »

 
%d bloggers like this: