how to use a 2-dimension string array?

  • Thread starter Thread starter fAnSKyer/C# newbie
  • Start date Start date
F

fAnSKyer/C# newbie

I know this question is stupid, but I really don't know how to do?

I am trying string[][] s = new string[10][10] and it is wrong?

Can someone give me a help? Or tell me where I can find answer, Thanks



Cheers

FAN
 
string [,] not string [][] if you have set sizes for both. [][] is a jagged
array (set on first dimension, different on second.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
 
[][] isn't a 2D array - it is a jagged array; you probably mean

string[,] s = new string[10,10];

Marc
 
Here is the jagged array syntax

string[][] strArray = new Array[10][];

HTH
Harry
 
Thanks, but I still got an error in
string k
s[cnt, ] = k.Split(' ');


when it is one dimension it works fine with s[] = k.Split(' ');


Thanks

Cheers
FAN
 
fAnSKyer/C# newbie said:
I know this question is stupid, but I really don't know how to do?

I am trying string[][] s = new string[10][10] and it is wrong?

Can someone give me a help? Or tell me where I can find answer, Thanks

You can't create a jagged array with array initializers for all
elements. Odd but true. The code to do what the above looks like it
should do is:

string[][] s = new string[10][];
for (int i=0; i < s.Length; i++)
{
s = new string[10];
}
 
I've figured out this question.

Thanks everybody :P

Cheers

FAN
"Cowboy (Gregory A. Beamer) дµÀ£º
"
string [,] not string [][] if you have set sizes for both. [][] is a jagged
array (set on first dimension, different on second.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

********************************************
Think outside the box!
********************************************
fAnSKyer/C# newbie said:
I know this question is stupid, but I really don't know how to do?

I am trying string[][] s = new string[10][10] and it is wrong?

Can someone give me a help? Or tell me where I can find answer, Thanks



Cheers

FAN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top