为什么我的VB.NET数组有额外的价值? [英] Why does my VB.NET array have extra values?

查看:149
本文介绍了为什么我的VB.NET数组有额外的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我宣布我的数组

Dim A(N) As Integer

当我从循环1到n 0到N-1 有一端有额外的价值或其他。

When I loop from 1 To N or 0 To N-1 there's an extra value at one end or the other.

这是怎么回事?

<子>(打算成为一个规范的问题/答案。)

推荐答案

在VB.NET阵列几乎总是有*下限 0 ,并声明在提到自己的上束缚,没有它们的长度。

In VB.NET arrays almost always* have a lower bound of 0 and are declared mentioning their upper bound, not their length.

他们做了改变VB.NET语法早早就允许你在需要提醒自己:

They did change the VB.NET syntax early on to allow you to remind yourself if needed:

Dim A(0 To N) As Integer

这是 0 不可能是其他任何东西(如 1 或常量零)。

That 0 can't be anything else (such as a 1 or a constant zero).

您可以通过使用所有VB.NET数组索引循环

You can loop through all VB.NET array indexes using

For i = LBound(A) To UBound(A)

,或者更简单地,

or, more simply,

For i = 0 To N

(*)可以使用.NET框架来创建其他较低界,但你需要用后期绑定(也可能是选项严格关以把它们称为阵列,从而)。

(*) You can use the .NET Framework to create arrays with other lower bounds, but you need to refer to them as Array and thus with late binding (and probably Option Strict Off).

这篇关于为什么我的VB.NET数组有额外的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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