two dimension array into one dimension.

rapitts

Member
Joined
Sep 24, 2008
Messages
5
Programming Experience
10+
Easy question....

If I have a two dimension array, something like this

atwodim[0,0] = 9.0
atwodim[0,1] = 8.0
atwodim[0,2] = 7.0
atwodim[0,3] = 6.0
atwodim[0,4] = 5.0
atwodim[1,0] = 9.0
atwodim[1,1] = 8.0
atwodim[1,2] = 7.0
atwodim[1,3] = 6.0
atwodim[1,4] = 5.0


Is there a quick .NET function to copy atwodim[1,] into a one dimension array, for example

aonedim = attwodim[0,]

So aonedim would contain the following :

aonedim[0] = 9.0
aonedim[1] = 8.0
aonedim[2] = 7.0
aonedim[3] = 6.0
aonedim[4] = 5.0

Thanks
 
I don't have a direct answer of whether you can redim a two dimensional array down to a one dimensional array (perhaps someone else can answer if they know).

But I can offer one option; create a user defined structure that holds two fields, you can then declare your structure as an array structure and fill it.
 
Thanks tom.

Structure sounds a good idea, I'm planning on holding 150 double elements in the array, I read somewhere that you should limit the structure to a max of 16 bytes?
 
I cant find anything that says that but again perhaps there is a better way of altering the array itself in the first place.
 
Easy question....

If I have a two dimension array, something like this

atwodim[0,0] = 9.0
atwodim[0,1] = 8.0
atwodim[0,2] = 7.0
atwodim[0,3] = 6.0
atwodim[0,4] = 5.0
atwodim[1,0] = 9.0
atwodim[1,1] = 8.0
atwodim[1,2] = 7.0
atwodim[1,3] = 6.0
atwodim[1,4] = 5.0


Is there a quick .NET function to copy atwodim[1,] into a one dimension array, for example

aonedim = attwodim[0,]

So aonedim would contain the following :

aonedim[0] = 9.0
aonedim[1] = 8.0
aonedim[2] = 7.0
aonedim[3] = 6.0
aonedim[4] = 5.0

Thanks
One of the ways to handle this would be to use a collection:
VB.NET:
Dim Numbers As New List(Of String)
For X As Integer = 0I To atwodim.GetUpperBound(0I)
    For Y As Integer = 0I To atwodim.GetUpperBound(1I)
        If Numbers.Contains(atwodim(X, Y).ToString) = False Then Numbers.Add(atwodim(X, Y).ToString)
    Next Y
Next X
Then to get the 1 dimensional array: Numbers.ToArray
 
Back
Top