Blog

Get the sequence of number from an array in C#

Coding Problems (C#)

Get the sequence of number from an array in C#

Get the sequence of number from an array in C#

				
					 int[] arr = { 1, 2, 3, 2, 4, 5, 2, 4 };

    var duplicates = arr.GroupBy(x => x)
        .Select(y => new { Item = y.Key, Count = y.Count() })
        .ToList();

    Console.WriteLine(String.Join("\n", duplicates));
				
			
dotnetcoaching, .net tutor, dotnet tutor, .net teacher

Please comment and share if you like this post and tell us about how we can enhance our posts. Thanks.

Subhajit