Search code examples
.netarrays

What is the purpose of Array.GetLowerBound(int)?


I don't understand the purpose of Array.GetLowerBound().

Does it ever return non-zero? When? How?

Thanks.


Solution

  • On a multi dimensional array in VB or various COM derived APIs you can query the lower bound by dimension. Array types can be 0 or 1 based (i.e. starting from zero or 1) and this applies to multidimensional arrays as well.

    This can also apply to arrays exposed through COM interop. For example, many Excel APIs use 1-based arrays and many APIs functions use variant arrays as parameters (the variant was essentially invented as a data type for a spreadsheet cell).

    When using COM interop you still have to play nicely with these APIs and type systems. They were originally designed to be used with VBA, and the 'classic' VB4-6 language variants had a truly baroque type system due to their tight coupling with COM. The .Net type systems of C# et. al. are somewhat less painful than their COM-based predecessors, but you still get to feel the pain when using COM interop.