I’m trying to figure out how many times the maximum value of an array occurs within the array by using Linq’s.Count() with a predicate inside. However, I don’t fully understand how to do it. From reading the MSDN’s scant example I thought I understood, but apparently not!
This is what I thought of:
string[] test = { "1", "2", "3", "4", "4" };
string max = test.Max();
Label1.Text = test.Count(p => p == max);
But that did not work. So I tried changing max to an integer to see if that would work, but that did not work either.
You could use the Where function to filter first then count: