0

I get this issue but i dont understand it completly. Found some suggestions online but seems they depend on the source code. This is my code and i get the error where the arrow is

            int j;
            float aa=0, modanum, count=0, temp;
            float[] mod =null;
            float[] fin = null;
            int[] arr = q.OfType<int>().ToArray();
            for(i=1;i<=n;i++)
            {
            for(j=1;j<=n;j++)
            {
      ----->    if(arr[i]==arr[j])
                count+=1;
            }

the array arr is delacred correctly and there are no resizes throught the process, this suggests that my arr is just not big enought, but for example i am sending a list q of 7 items and it still gets me when j=3.

4
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by deceptikon
0

may be the variable 'n' is more than array length, so even after your array elements are traced, the loop is stil alive, probably this might be the reason for the exception, how ever we cannot confirm this until we know what 'n' is.

0

The loops are a red flag for me because they count from 1 to n instead of from 0 to n-1. C# arrays are zero based, so even if n represents a safe limit for the array, you're still looking at an off by one error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.