Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multidimensional Arrays

Posted on 2008-10-08
10
Medium Priority
?
632 Views
Last Modified: 2013-12-17
I have created a multidimensional array:

string[,] strArray = new string[0,0];

I am tring to assign values to the array:

strArray [0, 0] = "Value1";

I am receiving the following error when assigning the values - "Index was outside the bounds of the array."

How do I resolve?
0
Comment
Question by:CipherIS
10 Comments
 
LVL 6

Expert Comment

by:xRalf
ID: 22669150
Hello CipherIS,

the problem is that your are has size [0, 0]. It is defined to contain 0 elements in both dimensions


Regards,

xRalf
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22669154
Hello CipherIS,

>string[,] strArray = new string[0,0];
Your array has 0 rows and 0 cols

change it to
string[,] strArray = new string[1,1];

Regards,

sunnycoder
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22669814
You are declaring a jagged array, would be better a traditional arrray as:

string[][] strArray = new string[1][1];
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 1

Author Comment

by:CipherIS
ID: 22671414
Ok this works with one value:
>string[,] strArray = new string[0,0];
Your array has 0 rows and 0 cols

change it to
string[,] strArray = new string[1,1];

 strArray [0, 0] = "Value1";
How do I add a second value:
strArray[0,1] = "Value2";    ?????
0
 
LVL 2

Accepted Solution

by:
Atbenning earned 1000 total points
ID: 22672392
Do you know how many rows/columns you're going to need?

If so, something like

string[][] strArr = new string[MAX_ROWS][MAX_COLUMNS];

is what you need, where MAX_ROWS and MAX_COLUMNS are > 0.

Then you can set with

strArr[x][y] = "valxy"  where MAX_ROWS > x >= 0 and MAX_COLUMNS > y >= 0
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 1000 total points
ID: 22674295
If you declare an with dimensions [x][y] then valid indices you can access are from [0][0] to [x-1][y-1]

>strArray[0,1] = "Value2";    ?????
So if you need to access [0,1] then you need to declare your array with minimum dimensions [1][2].

as Atbenning pointed out - new string[MAX_ROWS][MAX_COLUMNS]; is what you need.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 22876276
I am sorry for not having dropped by earlier ... a split would be fair.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question