Newby here.
I want to assign an array to an array of arrays (or jagged array).
I am doing the following:
Dim arrOutputData As Double() = New Double(0) {}
Dim arrOutputArray As Double()() = New Double(9)() {}
For intStepping As Integer = 0 To 9
arrOutputData(0) = intStepping
arrOutputArray(intStepping) = arrOutputData
Next intStepping
What I want is that arrOutputArray(0)(0)=0 on the first iteration, then arrOutputArray(1)(0)=1 on the second iteration, arrayOutputArray(2)(0)=2 and so forth.
What's actually happening is that arrOutputArray(0)(0)=0 on the first iteration, but the instant arrOutputData(0) is assigned 1 on the second iteration, arrOutputArray(0)(0) now equals 1 without even arriving at the line where arrOutputArray(1) = arrOutputData.
Tried this on vb.net 2008 and 2015 (on different computers) and I get the same result.
What am I doing wrong???
What bewilders me is that when the code reaches and executes arrOutputData(0)=1, immediately arrOutputArray(0)(0)=1. When the code reaches and executes the next line arrOutputArray(1)=arrOutputData, both arrOutputArray(0)(0) and arrOutputArray(1)(0) are now equal to 1.
Tried changing declaration syntax so Redim Preserve works, and still the same behaviour...
What gives?
Thanks!
Edit: I tried new code:
Dim arrInputData As Double() = New Double(intGlobalHistory) {}
Dim arrOutputData As Double() = New Double(0) {}
Dim arrInputArray As Double()() = New Double(intGlobalStepping)() {}
Dim arrOutputArray As Double()() = New Double(intGlobalStepping)() {}
For intStepping As Integer = 0 To intGlobalStepping
For intHistory As Integer = (intGlobalHistory + 1) To 1 Step -1
arrInputData(intHistory - 1) = dblSomeInputFactor + CDbl(intHistory)
Next intHistory
arrOutputData = New Double() {dblSomeOutputFactor + CDbl(intStepping)}
arrInputArray(intStepping) = arrInputData
arrOutputArray(intStepping) = arrOutputData
Next intStepping
While now the arrOutputData and arrOutputArray variables work great, the arrInputData and arrInputArray don't, in the sense that it's behaving like described in the first part of the question. Any ideas?
I feel like I must change something here to include the New keyword somehow:
arrInputData(intHistory - 1) = dblSomeInputFactor + CDbl(intHistory)
just not sure how or where exactly...