从一个数组生成多个数组 [英] generate number of arrays from one array

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

问题描述

我有一个整数数组,例如(1,8,9,8),我需要的是通过一次为每个项添加1来从中生成数组,以便第一个数组假设是(2,8,9,8)和第二个(1,9,9,8)等等。

Hi,I have an integer array for example (1,8,9,8),what i need is to generate number of arrays from it by add 1 to each item at a time so that the first array suppose to be (2,8,9,8) and the second (1,9,9,8) and so on .

Function myarray(ByVal arra1() As Integer, ByVal arran() As Integer, ByVal i As Integer) As Integer
        For i = 0 To arra1.Length - 1

            arran(i) = arra1(i)
            arran(i) = arra1(i) + 1
          Next
    End Function

推荐答案

你需要从函数中返回数组的数组(我已经返回了数组的List),因为你想得到的不仅仅是no。数组。



检查以下解决方案 -

You need to return array of array (I have returned List of array, instead) from your function as you want to get more than no. of arrays.

Check following solution-
Public Function myarray(arr As Integer()) As List(Of Integer())
	Dim resultarr As New List(Of Integer())()

	For i = 0 To arr.Length - 1
		Dim temparr As Integer() = arr
		temparr(i) = temparr(i) + 1
		resultarr.Add(temparr)
	Next

	Return resultarr
End Function





如果您的要求是其他原因,请告诉我。



希望,它有帮助:)



Please let me know if your requirement is something else.

Hope, it helps :)


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

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