2013-10-21 67 views
1

我想将一组值分隔为直方图图表的分档。我的直方图中会有10个垃圾箱。要排序和计算每个箱中的箱数,我正在使用一个数组。我得到的错误是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? 
       } 

      } 
+0

binct的数据类型是什么? – gleng

+0

我创建了数组来保持每个10箱的箱数的数量。它可以只是一个整数。 –

+0

查看Tigran的回答。您正在访问上述代码中索引为'idx'的对象,该对象是一个字符串数组。你不能增加一个字符串数组。我假设你正在尝试用k在for循环中做些什么? –

回答

3

这是一个简单:你的表达binct[idx]返回的类型不支持数值 操作像+++- ...

为了避免这种情况还有最后几个方面:

  • Operator overloading
  • 执行其他类型相同的操作那么这并映射的RE最后输入你想要的。
+0

所以我可以将其更改为int [] binct = new int [10]? –

+0

@RolandP:如果你现在更改了数组''int''',那么你可以对它的元素进行算术运算,因为它们是整数。 – Tigran

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; 
       } 

      } 
1

你试图递增一个字符串,它是没有意义的。让你的数组成为一个int数组