如何让基于1索引数组 [英] how to make 1-index based array

查看:147
本文介绍了如何让基于1索引数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题 - 如何使对象数组VB.NET与从1开始的索引

it is a simple question - how to make an object array in VB.NET with indexes starting from 1?

我需要这样一个对象的一系列写回一个Excel US preadsheet而且只接受1为基础的索引。

I need such an object to write back a range to an Excel spreadsheet and it accepts only 1-based indexing.

当我读Excel中的一个范围,它会自动创建在VB.NET基于1对象,但是当我试图创建另一个对象,它不允许我设置为LBOUND 1。

When I read a range from Excel, it creates a 1-based object in VB.NET automatically, but when I am trying to create another object, it doesn't allow me to set lBound as 1.

推荐答案

您可以使用 Array.CreateInstance 来实现你想要的。

You can use Array.CreateInstance to achieve what you want.

    ' 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

这篇关于如何让基于1索引数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆