473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C#NET2008 Problem with Two Dimensional Array

126 100+
Hullo Good Friends,
I need your help again. Please help me.

I am using C#NET2008 to develop application using Two Dimension Array to store String text and INT data.

These are the error messages:
Error #1 Index was outside the bounds of the array.
Error #2 Cannot implicitly convert type 'int' to 'string'

//declare Array variable
private string[ , ] strColmArray = new string[9, 1];


private void FLoadColmArray() {
strColmArray[0, 0] = "Order ID";
strColmArray[0, 1] = “Ord487”; <--- Error #1

strColmArray[1, 0] = “Product ID”;
strColmArray[1,1] = 750.45; - Error #2
}

--------------------------
Jan 2 '11 #1

✓ answered by GaryTexmo

Error #1 Index was outside the bounds of the array.
You've declared your array to have 9 rows and 1 column, then you are trying to access the second column. You need to declare the array with [9, 2] if you want to access the second column, the one with index 1.

Error #2 Cannot implicitly convert type 'int' to 'string'
That's actually a double (or a float) you're trying to put in there, and this error is because your array is a string. You either need to put quotes around that number, or use a different data type as your storage variable.

If you want to store two different data types in the same array, you'll either need to declare the array as an array of object, or create your own types that use inheritance and have the array be of the base type.

Hopefully that makes sense, please let me know if you have any questions.

2 1510
GaryTexmo
1,501 Expert 1GB
Error #1 Index was outside the bounds of the array.
You've declared your array to have 9 rows and 1 column, then you are trying to access the second column. You need to declare the array with [9, 2] if you want to access the second column, the one with index 1.

Error #2 Cannot implicitly convert type 'int' to 'string'
That's actually a double (or a float) you're trying to put in there, and this error is because your array is a string. You either need to put quotes around that number, or use a different data type as your storage variable.

If you want to store two different data types in the same array, you'll either need to declare the array as an array of object, or create your own types that use inheritance and have the array be of the base type.

Hopefully that makes sense, please let me know if you have any questions.
Jan 6 '11 #2
lenniekuah
126 100+
Hi Gary,
Thank you very much for sharing information wth me.
I used to develop application using ARRY in VB6 and was surprised that C#NET was different.

Your information has help me to learn new logic. Thank you very much for being generous and helpful in sharing information. You are awesome.
Jan 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
1
by: smurf | last post by:
Seems a simple question, but I can't find a simple answer: I have created a two dimensional array. I wish to send the data, a row at a time to a graph plotting routine which is expected a one...
4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
16
by: rguti | last post by:
Hi, How do I create a two dimensional array? I have created a one dimensional doing this: Dim laFields As ArrayList = New ArrayList How about to do a 2 dimensional?
5
by: Diffident | last post by:
Hello All, I have a 2-dimensional array that I am storing as a session variable. I have no idea on how I can cast the session variable back to 2-dimensional array. Any pointers? Reference...
4
by: Balaskas Evaggelos | last post by:
Hi, does anyone know how i can sort a multi-dimensional array by a specific field ? for example i want to sort arr where n=2, but i need the data of every array to follow that order. ...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.