简体   繁体   中英

Incrementing the values in an array

I am trying to separate a group of values into bins for a histogram chart. There will be 10 bins in my histogram. To sort and count the number of cases in each bin, I am using an array. The error I am getting is The operand of an increment or decrement operator must be a variable, property or indexer . idx will give me the bin number that needs to be incremented. I am just unsure of the proper way to increment it. Thank you for the suggestions and comments.

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

            }

This is a simple: the type returned by your expression binct[idx] does not support numerical operation like ++ , + - ...

To avoid this there are at last a couple of ways:

  • Operator overloading
  • Execute the same operation on other type then this and map the result to type you want.

What you can do is:

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

            }

You're trying to increment a string which makes no sense. Make your array an array of int instead

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM