如何制作基于1-index的数组
这是一个简单的问题 – 如何在VB.NET中创build索引从1开始的对象数组?
我需要这样一个对象来将范围写回Excel电子表格,并且只接受从1开始的索引。
当我从Excel中读取范围时,它会自动在VB.NET中创build一个基于1的对象,但是当我尝试创build另一个对象时,它不允许将lBound设置为1。
你可以使用Array.CreateInstance
来实现你想要的。
' create an array of 10 items with lower bound index of 1 Dim arrayStartingWith1 As Array = Array.CreateInstance(GetType(Integer), New Integer(0) {10}, New Integer(0) {1}) ' this is now incorrect ' arrayStartingWith1(0) = 1 ' this is correct arrayStartingWith1(1) = 1 arrayStartingWith1(10) = 1