I have a List<NameClass> that stores a collection of NameClass items with a property called Name in the class. What I’m trying to do is write a Linq query that will pull all the names that start with Jones, but only if there are 3 or more occurrences. For example, if my list had the following items:
Name
-----------
Jones
Jonestown
Smith
Hector
Jones
Smith
Smith
I am looking for a C# function that I can call like this:
GetNames("Jones");
And it should return:
Jones
Jonestown
Jones
And if I run this:
GetNames("Smith");
It should return:
Smith
Smith
Smith
And if I run this:
GetNames("Hector");
It should return nothing since Hector isn’t in the list 3 or more times.
Any help writing this LINQ query would be appreciated!
1 Answer