With reference to MSDN, It is stated that “You can set the lower bound of an Array, but the lower bound of an ArrayList is always zero”
If i declare an array a[10], the lower bound is always a[0].
Is this the lower bound specified there? If yes, How can we set the lower bound of an array, Since the index of an array always starts with a[0].
Or is the lower bound stated in the link is something different?
Note: I know the link point to the contents of .NET Framework 1.1 but still curious to know what exactly they have mentioned.
You can create an array with a non-zero lowerbound using
Array.CreateInstance.Note that you won’t be able to cast that to a
Foo[](whereFoois the relevant type) unless you also make it multidimensional. There are two types of array inside the CLR – a vector (zero based, single dimensional) and an array (can be multi-dimensional and have non-zero lower bound).A
T[]in C# always corresponds to a vector, whereas aT[][]corresponds to an array. So you can do:but this will fail:
Likewise you can’t cast it to
IEnumerable<int>orIList<int>– although you can iterate over it withIEnumerablejust fine.Personally I would avoid using non-zero lower-bounded arrays like the plague. They’re slow, and painful to work with.