以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]如何将数组2整体加入到数组1中 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=39556) |
-- 作者:loongtai -- 发布时间:2013/8/27 9:36:00 -- [求助]如何将数组2整体加入到数组1中 如题,加入后的结果为数组1的每个元素为一个数组 例如: arr2={1,2,3} arr3={4,5,6} 将arr2与arr3都加入到arr1中,期望得到的结果为 即: arr1(0)={1,2,3} arr1(1)={4,5,6} 而非 arr1(0)=1 arr1(1)=2 arr1(2)=3 arr1(3)=4 arr1(4)=5 arr1(5)=6 我借鉴http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=38815&skin=0 在命令窗口里试了下以下代码但是报错。 Dim arr1 As new List (of Integer()) Dim arr2() As Integer={1,2,3} Dim arr3() As Integer={4,5,6} arr1.add(arr2) arr1.add(arr3) For Each n As Integer() In arr1 output.show(n) Next |
-- 作者:Bin -- 发布时间:2013/8/27 9:44:00 -- Dim arr1 As New List(Of Integer) Dim arr2() As Integer = {1, 2, 3} Dim arr3() As Integer = {4, 5, 6} For i As Integer = 0 To arr2.Length - 1 arr1.Add(arr2(i)) Next For i As Integer = 0 To arr3.Length - 1 arr1.Add(arr3(i)) Next For Each n As Integer In arr1 output.show(n) Next
|
-- 作者:loongtai -- 发布时间:2013/8/27 10:10:00 -- [求助]自定义函数 以下是引用Bin在2013-8-27 9:44:00的发言: Dim arr1 As New List(Of Integer) Dim arr2() As Integer = {1, 2, 3} Dim arr3() As Integer = {4, 5, 6} For i As Integer = 0 To arr2.Length - 1 arr1.Add(arr2(i)) Next For i As Integer = 0 To arr3.Length - 1 arr1.Add(arr3(i)) Next For Each n As Integer In arr1 output.show(n) Next 我试了下 output.show("arr1.count=" & arr1.count) 得到的结果:arr1.count=6 这样得到的arr1应该是这样的:{1,2,3,4,5,6} 而我期望得到的是这样:{{1,2,3},{4,5,6}} arr1.count=2 [此贴子已经被作者于2013-8-27 10:12:05编辑过]
|
-- 作者:loongtai -- 发布时间:2013/8/27 10:11:00 -- [求助]自 [此贴子已经被作者于2013-8-27 10:12:52编辑过]
|
-- 作者:Bin -- 发布时间:2013/8/27 10:13:00 -- 那么你第一次发的代码就没有任何错误. 但是你是不可以直接那样输出的.既然是数组 你怎么可以直接 output.show 数组呢 Dim arr1 As new List (of Integer()) Dim arr2() As Integer={1,2,3} Dim arr3() As Integer={4,5,6} arr1.add(arr2) arr1.add(arr3) For Each n As Integer() In arr1 output.show(n.length) Next |
-- 作者:Bin -- 发布时间:2013/8/27 10:14:00 -- 如果想逐个输出那么应该这样 Dim arr1 As new List (of Integer()) Dim arr2() As Integer={1,2,3} Dim arr3() As Integer={4,5,6} arr1.add(arr2) arr1.add(arr3) For Each n As Integer() In arr1 For Each i As Integer In n output.show(i) Next Next |
-- 作者:loongtai -- 发布时间:2013/8/27 10:22:00 -- [求助]自定义函数 这次是我期望的结果 ,谢谢! [此贴子已经被作者于2013-8-27 10:23:30编辑过]
|