Duplicate Numbers using Lambda Expression in C#

Here I wrote code for finding repeated (Duplicate numbers) numbers using lambda expression in c#.

I know its easy but surely it will for beginners.

public static void repeated()

{

   int count=0;

   int[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 5, 9, 8, 10, 11, 12, 10, 13, 14, 15, 12, 16, 17, 18, 15, 19, 20 };

   var res = data.GroupBy(t => t);

 foreach(var t in res)

 {

     if (t.Count() > 1)

     {

        Console.WriteLine("The number " + t.Key + " repeated " + t.Count() + " times");

     }

   }

}


 

Ebook Download
View all
Learn
View all