in my application I have an array with 5000 elements. I have to sort these elements.But I am getting error of “Array index Out Of Bound Exception”.
Can anybody tell me what can be the maximum size for the array to sort?
Should I use ArrayList ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no specific limit – you are only constrained by memory here, and at this point the array already exists, so this isn’t a limitation of
Array.Sort. For example:I suspect you might (for example) have an
IComparable[<T>]implementation that is throwing an error internally? Or alternatively, perhaps this error has nothing at all to do withArray.Sort, and you have simply considered the wrong line as the cause.The exception’s
.StackTraceshould reveal everything, of course.And no: you shouldn’t use
ArrayListhere. Or pretty much anywhere else.