题
我试图找出多少次 最大值 一系列发生在列通过使用皇宫的.Count()
有一个判断的内部。不过,我不完全了解如何做到这一点。从读MSDN是少有的例子,我想我理解的,但显然不是!
这是我的想法:
string[] test = { "1", "2", "3", "4", "4" };
string max = test.Max();
Label1.Text = test.Count(p => p == max);
但是,没有工作。所以我试图改变 max 以整数以看到如果这会的工作,但没有工作。
解决方案
您可以使用其中的功能来过滤第一再算上:
Label1.Text = test.Where(p => p == max).Count().ToString();
其他提示
使用 Count(predicate)
是OK。你只需要返回值(这是一个整数)转换为字符串。
Label1.Text = test.Count(p => p == max).ToString();
int[] test = { 2, 45, 3, 23, 23, 4, 2, 1, 1, 1, 1, 23, 45, 45, 45 };
int count = test.Count(i => i == test.Max());
现在你有这就是你最终计计数。使得与一个int收藏更有意义。现在,来显示它,你可以调用toString()的数量。
尝试是这样的:
Label1.Text = test.Where(t => t == test.Max()).Count().ToString();
不隶属于 StackOverflow