一个数组问题 [英] An Array question

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

问题描述

大家好,

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

进口系统。字符串

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

推荐答案



" Edward" < Ed **** @ discussion.microsoft.com写了留言

新闻:ED ************************ ********** @ microsof t.com ...

"Edward" <Ed****@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...

大家好,

给我以下代码不应该工作,但确实如此!

进口system.String

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

Dim y(1)As String

y = x.Split(",")

TextBox1.text = y(3)

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



它的长度?

有什么想法吗?

-

祝你好运,

Edward
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


是的,但是我想知道这种行为背后的逻辑,当我们定义一个数组的固定大小时,我不知道它假设保持固定的大小?

实际上我们可以将一个更大的数组分配给一个更小的数组,并且VB不会是
complian并调整较小的数组的大小! br $> b $ b -

祝你好运,

爱德华

" Lloyd Sheen"写道:
yes but I was wondering about the logic behind this kind of behavior , when
we define a fixed size for an array isn''t it suppose to keep its fixed size ?
In fact we can assign a larger array to a smaller array and VB doesn''t
complian and resizes the smaller array!
--
Best regards,
Edward
"Lloyd Sheen" wrote:

>

" Edward" < Ed **** @ discussion.microsoft.com写了留言

新闻:ED ************************ ********** @ microsof t.com ...
>
"Edward" <Ed****@discussions.microsoft.comwrote in message
news:ED**********************************@microsof t.com...

大家好,

给我以下代码不应该工作,但确实如此!

进口system.String

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

Dim y(1)As String

y = x.Split(",")

TextBox1.text = y(3)

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



它的长度?

有什么想法吗?

-

祝你好运,

Edward
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


" Edward" < Ed **** @ discussion.microsoft.comschrieb:
"Edward" <Ed****@discussions.microsoft.comschrieb:

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

Imports system.String

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

Dim y(1)As String
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



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

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


y = x.Split(",")

TextBox1.text = y(3)

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


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?



''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/>


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

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