tags:

views:

90

answers:

2

When grouping numbers ,I use

   string[] numbers = 
   { "123", "34555", "91882", "100", "7823", "1111", "76551" };

    var query = from digits in numbers
                group digits by digits.Length into ByDigit
                select
                new { digit = ByDigit, length = ByDigit.Key };

When i suppose to use

var query = numbers.GroupBy() ( I do't know how to name it ,is it extension chaining ?)

what is the way to do it?

+6  A: 

I'm assuming that you want to know how to use the extension methods to do the same thing. In this case it would be

var query = numbers.GroupBy(n => n.Length).Select(n => new { digit = n, length = n.Key });
Blake Pettersson
oh! Yes I mean extension method
+4  A: 

Using same semantics, you'll have:

var query = numbers
    .GroupBy(digits => digits.Length)
    .Select(ByDigit => new
    {
        digit = ByDigit,
        length = ByDigit.Key
    });
Rubens Farias
You're too fast :)
GraemeF