ASP.NET 2.0 中的数组真的是固定长度的吗?
如果我dim
一个数组说,5个元素,如果我添加第6个元素,它不会失败吗?我认为这曾经需要redim
。在.NET 2.0中,我有一个长度= 3的字符数组。当我从数据库填充它时,一条记录中有4个字符,并且它成功地将所有4个字符添加到数组中?
If I dim
an array to say, 5 elements, should it not fail if I go to add a 6th? I thought this used to require a redim
. In .NET 2.0, I have a character array of length = 3. When I populate it from the db, one record had 4 characters in it and it successfully added all 4 characters to the array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将字符数组分配给包含数组(任意大小)的现有数组变量,它将创建所需大小的新数组。原始数组被垃圾收集。
If you assign an array of characters to an existing array variable containing an array (of any size), it creates a new array of the size that is required. The original array is garbage collected.
只是为了添加当前的答案,以防万一这是问题所在。在 VB.NET 中,您可以使用上限而不是所需的长度来声明数组。
例如:
此数组有 4 个元素,0 - 3。它的长度不与您在 C# 中所说的情况相同:
我不知道这是否是您的问题,但以防万一。
Just to add to the current answer, in case this was the problem. In VB.NET, you declare arrays with the upper bound, not the length desired.
For example:
This array has 4 elements, 0 - 3. It does not have a length of 3 as would be the case if you said this in C#:
I don't know if this is your issue, but just in case.