Jump to content

Help with Arrays

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Alex_j

Alex_j

    Newbie

  • Members
  • PipPip
  • 29 posts
Hi, I need to store more than one value in an array, is this possible?
e.g. I need to have:

int[] array=new int[4]

array[0]=2,4,6,8;

array[1]=3,6,9,12;

array[2]=5,10,15,20;

array[3]=1,3,17;

So each item in the array would be sort of an ID, then the numbers assigned to each item would be a position number.

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
You can initialize an array like this

int[] array = new int[4] { 1, 2, 3, 4, };

This is an array with four items in it. This array has four place holders called the array index. Indexes in programming always start with 0 so the indexes are 0, 1, 2, and 3. So if you reference array[0] you will see the number one. If you reference array[1] you will see the number two and so on. You can also do a multidimensional array like this:

int[,] array = new int[3, 2] { {1,2}, {3,4}, {5,6} };

For more information on arrays go here: http://msdn.microsof...3%28VS.71).aspx

Hope this helps.
-CDG10620
Software Developer

#3
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
You can also do an Array of Arrays (jagged arrays)
http://msdn.microsof...a%28VS.80).aspx
jaggedArray[0] = [COLOR=Blue]new[/COLOR] [COLOR=Blue]int[/COLOR][] { 1, 3, 5, 7, 9 };
jaggedArray[1] = [COLOR=Blue]new[/COLOR] [COLOR=Blue]int[/COLOR][] { 0, 2, 4, 6 };
jaggedArray[2] = [COLOR=Blue]new[/COLOR] [COLOR=Blue]int[/COLOR][] { 11, 22 };


#4
tofurocks

tofurocks

    Newbie

  • Members
  • Pip
  • 3 posts
Oh, so THAT'S how jagged/multidimensional arrays work..
Always heard about them but never knew how to use them @.@
Thanks for the link PGP.