Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Group elements of array to get a count of each. Lambda expression in C#

how do I do this with a lambda expression?
int[] n1 = new int[18] { 5, 9, 1, 2, 3, 7, 5, 6, 7, 3, 7, 6, 8, 5, 4, 9, 6, 2 };
            var nQuery =
            from VrNum in n1
            group VrNum by VrNum into y
            select y;
            foreach (var i in nQuery)
                Console.WriteLine("Number " + i.Key +" appears " +i.Count()+" times.");

Open in new window

Avatar of Bill Prew
Bill Prew

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlHal2