在我的代码中,我有一个名为array的arraylist.
我已经填写了1到13的数字
for(int i =1; i< 14; i++)
{
array.items.Add(i)
}
Run Code Online (Sandbox Code Playgroud)
稍后在我的代码中我也随机删除了一些元素.示例array.remove(3);
现在我想搜索一下,arraylist中元素的多少值超过了特定的数字.
那么,arraylist中有多少元素结束了例如5.
谁知道怎么做?
谢谢!
使用这个lambda表达式:
int count = array.Cast<int>().Where(e=> e > 5).Count();
Run Code Online (Sandbox Code Playgroud)
甚至更简单:
int count = array.Cast<int>().Count(e=> e > 5);
Run Code Online (Sandbox Code Playgroud)
你必须来自Java吗?我相信你应该List<T>在c#中使用a .