How to count the frequency of bundle of number using c#?

前端 未结 5 1150
遇见更好的自我
遇见更好的自我 2020-12-12 06:21

Can somebody help me to run this program using c#. This program is to calculate the frequency of the number, for example 12 appear 10x. Before this I try to sort all list

5条回答
  •  无人及你
    2020-12-12 07:23

    I would put them all into a list then use a group by clause to group them ie

            List numbers = new List { 1, 2, 2, 3, 5, 6, 2, 1, 4, 4 };
            foreach (var group in numbers.GroupBy(n => n))
            {
                Console.WriteLine("{0} was found {1} times", group.Key, group.Count());
            }
    

提交回复
热议问题