Connecting Tech Pros Worldwide Help | Site Map

Multi-dimensional Arrays... Not working...

Member
 
Join Date: Sep 2009
Location: Usa, Michigan, Westland
Posts: 49
#1: Oct 8 '09
I've tried every combination from the MSDN reference on Multi-Dimensional arrays. They say it works, it doesn't on my MS VS '08... This is the last attempt that I made 4 minutes ago.

Help!

Expand|Select|Wrap|Line Numbers
  1. string[,] TDisc = new string[][] {
  2.      new string[] { "Disc Col 1 Row 1", "Disc Col 1 Row 2" },
  3.      new string[] { "Disc Col 2 Row 1", "Disc Col 2 Row 2", "Disc Col 2 Row 3" },
  4.      new string[] { "Disc Col 3 Row 1", "Disc Col 3 Row 2", "Disc Col 3 Row 3", "Disc Col 3 Row 4", "Disc Col 3 Row 5" }
  5. };
Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 211
#2: Oct 8 '09

re: Multi-dimensional Arrays... Not working...


You're so close :D

Your variable type needs to match what you put into it. In your case, you're trying to put an object of type string[][] into a variable of type [,], which is two different things.

For your example, the simplest solution would be to change the variable to match the type of object you're putting into it; that is,

Expand|Select|Wrap|Line Numbers
  1. string[][] TDisc = new string[][] { ...
You can verify the contents of your multidimensional array via...

Expand|Select|Wrap|Line Numbers
  1.             foreach (string[] arr in TDisc)
  2.             {
  3.                 foreach (string str in arr)
  4.                 {
  5.                     Console.WriteLine(str);
  6.                 }
  7.                 Console.WriteLine();
  8.             }
If you want to use a multidimensional array accessed via array[d1, d2, ..., dn] then you need to declare it in that fashion.

I'm not sure which page you were looking at, but it's pretty clearly explained at this MSDN page: http://msdn.microsoft.com/en-us/libr...8VS.71%29.aspx

Good luck!
Member
 
Join Date: Sep 2009
Location: Usa, Michigan, Westland
Posts: 49
#3: Oct 8 '09

re: Multi-dimensional Arrays... Not working...


Gary saves the day yet again for me!
Thanks!!!
Reply