1

我正在尝试将一组值分成直方图的箱。我的直方图中将有 10 个 bin。为了对每个箱子中的案例数量进行排序和计算,我使用了一个数组。我得到的错误是The operand of an increment or decrement operator must be a variable, property or indexer. idx 会给我需要增加的 bin 编号。我只是不确定增加它的正确方法。感谢您的建议和意见。

            int binsize = Convert.ToInt32(xrLabel101.Text) / 10;//Max divided by 10 to get the size of each bin
            this.xrChart4.Series[0].Points.Clear();
            int binCount = 10;
            for (int i = 0; i < binCount; i++)
            {
                int m = Convert.ToInt32(xrLabel104.Text);//This is the number of loops needed
                string[] binct = new string[10];

                for (int k = 0; k < m; k++)
                {
                    int idx = Convert.ToInt32(currentcolumnvalue) / binsize;
                    binct[idx]++;//I know this is wrong. Suggestions?
                }

            }
4

3 回答 3

3

这很简单:您的表达式返回的类型binct[idx]不支持数字运算,例如+++ -...

为了避免这种情况,最后有两种方法:

  • 运算符重载
  • 对其他类型执行相同的操作,然后将结果映射到您想要的类型。
于 2013-10-21T20:06:09.703 回答
2

你可以做的是:

            int binsize = Convert.ToInt32(xrLabel101.Text) / 10;//Max divided by 10 to get the size of each bin
            this.xrChart4.Series[0].Points.Clear();
            int binCount = 10;
            for (int i = 0; i < binCount; i++)
            {
                int m = Convert.ToInt32(xrLabel104.Text);//This is the number of loops needed
                int[] binct = new int[10];

                for (int k = 0; k < m; k++)
                {
                    int idx = Convert.ToInt32(currentcolumnvalue) / binsize;
                    binct[idx] = binct[idx] + 1;
                }

            }
于 2013-10-21T20:09:26.177 回答
1

您正在尝试增加一个没有意义的字符串。将您的数组改为 int 数组

于 2013-10-21T20:09:53.407 回答