帮助计算List<>中的数据 [英] Help on counting data from List<>

查看:62
本文介绍了帮助计算List<>中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助..

我需要计算数据取决于我列表中的条件...问题是当我显示计数时,它总是返回0

这是我的代码..



Please help..
I need to count data depends on condition in my List... problem is when i am displaying the count, it always return 0
this is my code..

List<int> range = new List<int>();
            List<int> frequency = new List<int>();

            int b = (int)numericUpDown1.Value;
            int c = (int)numericUpDown2.Value;
            int d = (int)numericUpDown3.Value;

            for (int i = 1; i < d + 1; i++)
            {
                
                int r = ((c - b) / d) * i;
                int s = ((c - b) / d) * (i - 1);
                int t = 0;
                range.Add(r);
                
                for (int j = 0; j < listOfNumbers.Count; j++)
                {
                    if (listOfNumbers[j] >= s && listOfNumbers[j] <= r)
                    {
                        t = t+1;
                    }
                    frequency.Add(t);
                }
            }


            for (int u = 0; u < d; u++)
            {
                listBox1.Items.Add(range[u]);
                listBox2.Items.Add(frequency[u]);
            }

推荐答案

我已经有了解决方案....



I already got the solution....

List<int> range = new List<int>();
List<int> frequency = new List<int>();

int b = (int)numericUpDown1.Value;
int c = (int)numericUpDown2.Value;
int d = (int)numericUpDown3.Value;

for (int i = 1; i < d + 1; i++)
{

    int r = ((c - b) / d) * i;
    int s = ((c - b) / d) * (i - 1);
    int t = 0;
    range.Add(r);

    for (int j = 0; j < listOfNumbers.Count; j++)
    {
        if (listOfNumbers[j] >= s && listOfNumbers[j] <= r)
        {
            t = t+1;
        }
        //frequency.Add(t);
    }
    frequency.Add(t);
}


for (int u = 0; u < d; u++)
{
    listBox1.Items.Add(range[u]);
    listBox2.Items.Add(frequency[u]);
}


这篇关于帮助计算List&lt;&gt;中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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