how to get the number of repetitions from List<int>

c#, linq, linq-to-sql

Solution

var query1 = from a in ListIdProducts 
                         group a by new { a } into g
                         select new
                         {
                             item = g.Key,
                             itemcount = g.Count()
                         };

Problem

``` List<int> ListIdProducts = new List<int>(); var IdProductKey = from a in me.ProductKeywords where a.Keyword == item.Id select a; foreach (var item2 in IdProductKey) { ListIdProducts.Add(item2.Product.Value); } ``` Result is: 5 6 7 5 2 5 I need to get the following 5=3, 6=1, 7=1, 2=1

Original source