Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Friday, September 25, 2009

System.IndexOutOfRangeException was unhandled (Message="Index was outside the bounds of the array.")

on C# or vb.net we are using array,Array is one of the best way to mentain collection of data together and proper way ,

here is one Error which get call whenever some problem with size and all

The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array. This class cannot be
inherited.

.NET arrays have base 0 and should be kept in mind when coding.


ones you got this error you have to resize your array size, accroding to your requirements

Tuesday, September 22, 2009

How to get the Upper Bound of an Array in C#

hi, if you'r using asp, vbscript and all then you have option call UBound
which will return a UpperBound value of Array. but on C#, you dont have that option call Ubound ,for that you can use GetUpperBound() option - Gets the upper bound of the specified dimension in the Array.

here is an Example which can show how to use GetUpperBound()


For i = MyArray.GetLowerBound(0) To MyArray.GetUpperBound(0)

Next i


like this way you can use both option call GetLowerBound & GetUpperBound ,
GetLowerBound will return lower bound value.here you have to pass (int value)
0 - 1st arrayvalue, 1- 2ndarrayvalue like that,

thank you.