.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

LINQ - Group By

Posted By:BitWise       Posted Date: August 25, 2012    Points: 40    Category: LINQ    URL: http://www.dotnetspark.com  

Group by is used to partition a list of numbers by their remainder when divided by 5.
 

public void Linq40() 
    { 
        int[] number = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; 
      
        var numbers = 
            from n in number 
            group n by n % 5 into group 
            select new { Remainder = group.Key, Numbers = group }; 
      
        foreach (var group in numbers) 
        { 
          foreach (var n in group.Numbers) 
            { 
                Console.WriteLine(n); 
            } 
        } 
    }

     

Further Readings:

Responses
Author: Ravi Ranjan Kumar         Company URL: http://www.dotnetspark.com
Posted Date: August 31, 2012

Nice effort. will you please elaborate your codes.

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend