Created
February 17, 2018 11:34
-
-
Save joshi-kumar/c06cf4acb608643f645e962044ebd009 to your computer and use it in GitHub Desktop.
Count duplicate value in List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ListbrandList = new List<String>() { | |
"Joshi", | |
"Vikas", | |
"Joshi", | |
"Vikas", | |
"Sharma", | |
"Anuj", | |
"Joshi", | |
}; | |
var result = ListbrandList | |
.GroupBy(item => item) | |
.Select(item => new { | |
Name = item.Key, | |
Count = item.Count() | |
}) | |
.OrderByDescending(item => item.Count) | |
.ThenBy(item => item.Name); | |
String report = String.Join(Environment.NewLine, result | |
.Select(item => String.Format("{0} appears {1} time(s)", item.Name, item.Count))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment