473,466 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to use a 2-dimension string array?

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

Nov 30 '06 #1
8 5264
[][] isn't a 2D array - it is a jagged array; you probably mean

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

Marc
Nov 30 '06 #2
Mel
try
string[,] s = new string[10,10];
"fAnSKyer/C# newbie" <fa******@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
>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

Nov 30 '06 #3
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
Marc Gravell wrote:
[][] isn't a 2D array - it is a jagged array; you probably mean

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

Marc
Nov 30 '06 #4
fAnSKyer/C# newbie <fa******@gmail.comwrote:
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[i] = new string[10];
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 30 '06 #5
Here is the jagged array syntax

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

HTH
Harry

"fAnSKyer/C# newbie" <fa******@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
>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
Nov 30 '06 #6
More info:
http://msdn2.microsoft.com/en-us/library/9b9dty7d.aspx

Note that you can set individual jagged portions:

string[][] ary = new string[10][];
ary[0] = new string[10];

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

********************************************
Think outside the box!
********************************************
"fAnSKyer/C# newbie" <fa******@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
>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
Nov 30 '06 #7
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" <fa******@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
>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
Nov 30 '06 #8
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" <fa******@gmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
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
Dec 1 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Goh, Yong Kwang | last post by:
I'm trying to create a function that given a string, tokenize it and put into a dynamically-sized array of char* which is in turn also dynamically allocated based on the string token length. I...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
17
by: Roshawn | last post by:
Hi, I have a small function that uses a For...Next loop. I am trying to place the results of the loop in a string array. My code is as follows: Dim i as Integer Dim str() as String For i =...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
1
by: dotnetnoob | last post by:
i have a arraylist that store String() array the string array hold value 1 2 4 i want to access the string array that is inside the arraylist one arraylist item at the time i search up and...
10
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! Got a simple question. I am new to c# but this is not making me any sence. If i declare: string myStringArray = new string; How the heck could i fill it with more than one element? ...
6
by: Arnshea | last post by:
(apologies for the crosspost) I'm working with an MFC based COM object. From C# I'd like to be able to call a method on the COM object that takes a string array and modifies the contents. Is...
2
by: LinLMa | last post by:
Hello everyone, I find strange result in the following program. 1. For string array, dereferencing it will result in the string itself, but for int array, dereferencing it will result in the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.