获取数组内部数组的最大数量? [英] Get the max count of an array inside array?

查看:58
本文介绍了获取数组内部数组的最大数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数组中有一个数组,我想获得该数组的最高计数,

I have an array inside the array and I want to get the Highest count of that Array,

List<int> badnumber = new List<int>() { 5,4,2, 15 };
int lower = 1;
int upper = 10;

int count = 0;

List<int> goodnumber = new List<int>();
List<List<int>> myList = new List<List<int>>();

for (int i = lower; i <= upper; i++)
{
    if (!badnumber.Contains(i))
    {
        if (!goodnumber.Contains(i))
            goodnumber.Add(i);
    }
    else
    {
        myList.Add(goodnumber);
        goodnumber = new List<int>();
    }

    if (i == upper) {
        myList.Add(goodnumber);
    }
}

myList 值中的

就像这样

Array 1 : { 1 }
Array 2 : { 3 }
Array 3 : { 0 }
Array 4 : { 6, 7, 8, 9, 10 }

我想获取数组4的最高序列的计数,并返回其序列5的计数.

I want to get the count of the highest sequence which is Array 4. and return the count of it which is 5.

我怎么得到那个?

推荐答案

使用以下示例

    var maxCount = myList.Max(l => l.Count);

这篇关于获取数组内部数组的最大数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆