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();
      ----->    if(arr[i]==arr[j])

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.

Recommended Answers

What's n? Why aren't you using the size of the array as the limit?

Jump to Post

All 3 Replies

What's n? Why aren't you using the size of the array as the limit?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.