VB.NET数组=数组 [英] VB.NET array = array

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

问题描述

我正在尝试创建一个程序,在其中将数组分配给数组.它们被这样声明:

I'm trying to create a program in which I'm assigning array to array. They are declared like that:

Const Deck_Size = 52

Const Deck_Size = 52

私有Deck(Deck_Size),Table_Deck(Deck_Size)作为字符串

Private Deck(Deck_Size), Table_Deck(Deck_Size) As String

所以,在我的程序中,我写了这一行:

So, in my program I have written this line:

平台= Table_Deck

这是做什么的,我如何从得到的结果中了解到,"Table_Deck"指针已分配给"Deck".例如

And what this does, how i can understand from results I'm getting, that "Table_Deck" pointer have been assign to "Deck". For e.g.

Table_Deck ="As","Ks","Qs","Js",...

Table_Deck = "As","Ks","Qs","Js",...

Deck ="2h","3h","4h","5h",...

Deck = "2h", "3h", "4h", "5h",...

此代码行之后:Deck = Table_Deck,我有这个:

After this code line: Deck = Table_Deck, I have this:

Table_Deck ="As","Ks","Qs","Js",...

Table_Deck = "As","Ks","Qs","Js",...

Deck ="As","Ks","Qs","Js",...

Deck = "As","Ks","Qs","Js",...

问题来了.

完成下一行代码后( Table_Deck(1)= Table_Deck(4)),我得到以下结果: Table_Deck ="Js","Ks", "Qs","Js",... ,但"Deck"也有变化...

When the next code line is done (which is: Table_Deck(1) = Table_Deck(4)), I get this result: Table_Deck = "Js","Ks","Qs","Js",..., but as well "Deck" changes too...

甲板="Js","Ks","Qs","Js",...

所以,我认为这是指针错误.如果我只想更改一个数组中的元素,谁能告诉我如何解决这个问题.

So, I assume that this is pointers fault. Can anyone tell me how I can solve this problem, if I want to change element in only one array.

推荐答案

正确,您的分配更改了数组引用.之后,Deck和Table_Deck都引用完全相同的数组.因此,您对Deck内容所做的任何更改也将通过Table_Deck引用可见.您必须复制内容:

Right, your assignment changes the array reference. Afterwards, both Deck and Table_Deck reference the exact same array. So any changes you make to Deck's content will be visible through the Table_Deck reference as well. You have to copy the content instead:

    Table_Deck.CopyTo(Deck, 0)

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

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