Answer the question
In order to leave comments, you need to log in
How to count the number of matching objects using LINQ?
There is an array Person[]
Person:
class Person
{
public string Name {get; set;}
public DateTime BirthDate {get; set:}
}
Answer the question
In order to leave comments, you need to log in
var persons = new[]
{
new { Name = "Юрий Васильевич Кондратюк", BirthDate = new DateTime(1897, 06, 9) },
new { Name = "Михаил Фёдорович Решетнёв", BirthDate = new DateTime(1924, 11, 10) },
new { Name = "Михаил Тимофеевич Калашников", BirthDate = new DateTime(1919, 11, 10) },
new { Name = "Сергей Павлович Королёв", BirthDate = new DateTime(1907, 1, 12) },
new { Name = "Михаил Васильевич Ломоносов", BirthDate = new DateTime(1711, 11, 8) }
};
int[] arr = persons.Where(n => n.Name.Contains("Михаил"))
.GroupBy(day => day.BirthDate.Day)
.Select(count => count.Count())
.ToArray();
Array.ForEach(arr, Console.WriteLine);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question