本文介绍了一个数组问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

对我来说,下面的代码应该不行,但确实如此!

进口系统。字符串

Dim x As String =" This,is,a,test"

Dim y(1)As String

y = x.Split(",")

TextBox1.text = y(3)

为什么Y这是一个长度为2的数组,接受索引3大于

它的长度?

有什么想法吗?

-

祝你好运,

爱德华

Hi everybody,
To me the following code shouldn''t work but it does !
Imports system.String
Dim x As String="This,is,a,test"
Dim y(1) As String
y=x.Split(",")
TextBox1.text=y(3)
why "Y" which is an array of lenght 2 accepts index 3 which is larger than
its lenght?
Any thoughts?
--
Best regards,
Edward

推荐答案



声明:

y = x.Split(",")

创建一个新数组并将其分配给y。第一个作业允许

项目(0)和(1)。重新分配(split语句)只返回一个

数组,其大小取决于源字符串和拆分字符串。


LS

The statement:
y=x.Split(",")

creates a new array and assigns it to y. The first assignment allows for
items (0) and (1). The reassignment (the split statement) just returns an
array the size of which depends on the source string and the split string.

LS




声明:

y = x.Split(",")

创建一个新数组并将其分配给y。第一个作业允许

项目(0)和(1)。重新分配(split语句)只返回一个

数组,其大小取决于源字符串和拆分字符串。


LS


The statement:
y=x.Split(",")

creates a new array and assigns it to y. The first assignment allows for
items (0) and (1). The reassignment (the split statement) just returns an
array the size of which depends on the source string and the split string.

LS




=''Dim y()As String''。

=''Dim y() As String''.



''Y''引用一个长度为4的数组,其中指数为0,...,3,

赋值''拆分'''的返回值。 ''Y(3)''包含test。


-

MS Herfried K. Wagner

MVP < URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>

''Y'' references an array of length 4 with indices 0, ..., 3 after the
assignment of ''Split''''s return value. ''Y(3)'' contains "test".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于一个数组问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 16:04