Take the 2-minute tour ×

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:

share|improve this question
Are you trying to create a matrix (e.g., an array of 12 arrays, for a total of 144 elements)? –  Eric Lloyd Sep 17 '13 at 4:54
thanks for responding...no just 12 arrays –  user1222646 Sep 17 '13 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. –  Eric Lloyd Sep 17 '13 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 –  user1222646 Sep 17 '13 at 5:04
I think I can better help if I have more context. Why do you need twelve arrays? What are you storing? –  Eric Lloyd Sep 17 '13 at 5:05

1 Answer 1

Why not just make a single two-dimensional array?

int[][] monthArrays = new int[12][];
    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
share|improve this answer
Exactly what I was getting to. –  Eric Lloyd Sep 17 '13 at 5:30

Your Answer


