i want to get the index of array which causes indexOutOfRangeException .

Well to get this exception you must be referring to the array location in some form (a loop or direct call) that goes past the length, therefore the index of what is causing the issue will be blatently obvious if you debug your code.

Array.Length returns an integer representing how many entries are in the array. The array however starts at 0 not 1 and so the length will always be one less than this as the length count starts at 1.

It is also worth noting 2d arrays and larger count each entry as in the array so a 2d array of size 10 will have a length of 20. Therefore a divide is needed on the length if you were to loop through it.

Be a part of the DaniWeb community

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