Here I need to get the total count of name Murugan my output should be "2" . How to write Linq Query for that
Linq:
Person[] names = {new Person { Name = "Murugan", Money = 15000 },
new Person{Name="Vel",Money=17000},
new Person{Name="Murugan",Money=1000},
new Person{Name="Subramani",Money=18000},
new Person{Name="Vel",Money=2500}};
var result = from val in names
where val.Name == "Murugan"
select val;
Console.WriteLine(result);
Console.ReadLine();
try this:
var count = names.Count(x=>x.Name=="Murugan");
You can use this,
var result = (from val in names
where val.Name == "Murugan"
select val).Count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With