VB]如何仅使用一个索引访问2D数组? [英] VB] How to Access a 2D array with only one Index ?
本文介绍了VB]如何仅使用一个索引访问2D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。
我想访问只有一个索引的2D数组。
这个方法在C ++中成为可能,我不知道如何在VB中...
谢谢..
在C ++中>
Hello.
I want to access a 2D array with only one Index.
This approach is made possible in "C++", I do not know how to in "VB"..
Thank you..
In C++>
char cTestArr[2][10];
strncpy(cTestArr[0],"123456789\0",10); // Data -> char array ( PASS! )
CString strTest(cTestArr[0]); // char array -> CString ( PASS! )
在VB>
In VB>
Dim strTemp As String
Dim cTestArr(2, 10) As Char ' Must not be a String Type
cTestArr(0) = "123456789" ' Data -> char array ( FAIL!!! )
strTemp = cTestArr(0) ' char array -> String ( FAIL!!! )
推荐答案
你没有。您必须使用两个索引。在C中,你可以逃脱它,但VB更严格。
如果你想使用一个索引的解决方案是使它成为一维的阵列。你将不得不做一些额外的数学编码来使用两个索引来访问数组并生成一个索引值以从数组中获取正确的项。
You don't. You have to use two indexes. In C, you can get away with it, but VB is a lot more strict.
The solution if you want to use one index is to make it a one dimensional array. You'll have to do some additional mathematical coding to access the array using two indexes and generate a single index value to get the correct item from the array.
这篇关于VB]如何仅使用一个索引访问2D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文