Skip to content

Instantly share code, notes, and snippets.

@joshi-kumar
Created February 17, 2018 11:34
Show Gist options
  • Save joshi-kumar/c06cf4acb608643f645e962044ebd009 to your computer and use it in GitHub Desktop.
Save joshi-kumar/c06cf4acb608643f645e962044ebd009 to your computer and use it in GitHub Desktop.
Count duplicate value in List
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