0

I am just trying to learn razor syntax for webmatrix and I am struggling with arrays and cant find any guidance, can someone show me where I am going wrong..cheers

 @for(var i = 1; i < 13; i++) {   

    int[] new monthArray[i];

  }

I need to create 12 arrays named as:

monthArray1
monthArray2
monthArray3
.......
monthArray12
7
  • Are you trying to create a matrix (e.g., an array of 12 arrays, for a total of 144 elements)? Commented Sep 17, 2013 at 4:54
  • thanks for responding...no just 12 arrays Commented Sep 17, 2013 at 4:55
  • Right now, what you're doing is re-declaring the same array in each pass through the loop, each time one element longer, then throwing it all away because you're declaring the variable inside the loop. Commented Sep 17, 2013 at 4:59
  • thanks..so how do i code this so its not the same array and i am declaring a new one with an incrementing name on each loop Commented Sep 17, 2013 at 5:04
  • I think I can better help if I have more context. Why do you need twelve arrays? What are you storing? Commented Sep 17, 2013 at 5:05

1 Answer 1

1

Why not just make a single two-dimensional array?

int[][] monthArrays = new int[12][];
@for (var i = 1; i < 13; i++) {
    monthArrays[i] = new int[foo]; // foo is length of each array
}

Then, access the right array by month number.
For example, instead of monthArray3, you'd write

monthArrays[3] ... // do something with array
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was getting to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.