I need to create a multi dimensional array of strings in C# like-
tiger elephant pigeon lion ant peacock
I'm unable to create. It either flags an error or throws an exception at the run time. Please help me with it, by giving the correct syntax.
-
1Please post your code so we can track better.Shamim Hafiz - MSFT– Shamim Hafiz - MSFT2011年05月06日 06:57:32 +00:00Commented May 6, 2011 at 6:57
-
1why don't you accept any ans?Badr– Badr2011年05月06日 09:52:59 +00:00Commented May 6, 2011 at 9:52
4 Answers 4
string[] animals = new string[]{"tiger", "elephant", "pigeon", "lion", "ant", "peacock"};
Am not sure I understand the question, the above doesn't appear to be a multidimensional array.
Do you simply want somthing along the lines of the below?
string[] animals = {"tiger", "elephant"};
answered May 6, 2011 at 6:58
Will A
25k5 gold badges54 silver badges61 bronze badges
Comments
string[,] siblings = new string[2, 2] { {"Mike","Amy"}, {"Mary","Albert"} };
and also look for jagged array
answered May 6, 2011 at 6:59
Badr
10.7k16 gold badges73 silver badges105 bronze badges
Comments
Here is an example of how to create multi-dimensional string array and have it initialized:
string[] myStringArray = new string[] { tiger, elephant, pigeon, lion, ant, peacock};
answered May 6, 2011 at 6:59
Shamim Hafiz - MSFT
22.2k44 gold badges122 silver badges183 bronze badges