473,320 Members | 1,920 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,320 software developers and data experts.

array with multiple datatypes, how?

Dear experts!

..NET 2.0

I'm trying to make an array containg multiple datatypes. This array will
consist of 3 items (string, string, integer):

my first try was this, (of course it fails)
string[] param = new string[3];
param[0] = "2007-08-01";
param[1] = "2007-08-31";
param[2] = "0";

any suggestions on how to create such an array containing items of different
datatypes are most welcome :)

Jeff
Aug 24 '07 #1
6 5530
Hi Jeff

The simplest way would be to declare the type as object eg.

object[] param = new object[3];
param[0] = "2007-08-01";
param[1] = "2007-08-31";
param[2] = 0;

The array can then contain ANY .Net type e.g. Int, String, Control, Form
etc....

HTH

Ged
"Jeff" <do***@spam.mewrote in message
news:O0****************@TK2MSFTNGP05.phx.gbl...
Dear experts!

.NET 2.0

I'm trying to make an array containg multiple datatypes. This array will
consist of 3 items (string, string, integer):

my first try was this, (of course it fails)
string[] param = new string[3];
param[0] = "2007-08-01";
param[1] = "2007-08-31";
param[2] = "0";

any suggestions on how to create such an array containing items of
different datatypes are most welcome :)

Jeff
Aug 24 '07 #2
or short-hand:

object[] args = { "abc", "def", 123 };

Marc

Aug 24 '07 #3
Do not forget to cast to the appropriate datatype when reading out the
objects

// Store
object[] param = { "abc", "def", 123 };

// Read
string s0 = (string)param[0];
string s1 = (string)param[1];
int i = (int)param[2];

Joachim
Aug 24 '07 #4
"jo*****@yamagata-europe.com" <jo*****@yamagata-europe.comwrote in
news:11**********************@q4g2000prc.googlegro ups.com:
Do not forget to cast to the appropriate datatype when reading out the
objects

// Store
object[] param = { "abc", "def", 123 };

// Read
string s0 = (string)param[0];
string s1 = (string)param[1];
int i = (int)param[2];
Hi, I've seen this sort of thing in parameters to methods before, and I was
wondering what the benefit is with using an "array of objects" instead of
defining your own type (fx a class) to hold the string/string/int values?
Aug 24 '07 #5
Hi, I've seen this sort of thing in parameters to methods before, and I was
wondering what the benefit is with using an "array of objects" instead of
defining your own type (fx a class) to hold the string/string/int values?
You can create an struct who had some fields to hold string/int and so
on.
But it will fixed to that type of fields, the objects array is
completly generic (dont in the generics** sense)
any type cast to object!

Aug 24 '07 #6
bob
On Fri, 24 Aug 2007 11:18:02 +0200, "Jeff" <do***@spam.mewrote:
>Dear experts!

.NET 2.0

I'm trying to make an array containg multiple datatypes. This array will
consist of 3 items (string, string, integer):

my first try was this, (of course it fails)
string[] param = new string[3];
param[0] = "2007-08-01";
param[1] = "2007-08-31";
param[2] = "0";

any suggestions on how to create such an array containing items of different
datatypes are most welcome :)

Jeff
Hi Jeff,
you could stay with the above code and use the tryParse method of each
of the datatypes when pulling your values out. (Assuming not too many
datatypes otherwise it becomes unwieldy.)

Bob
Aug 27 '07 #7

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

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
7
by: Brian P | last post by:
I am getting an invalid cast exception when I try to take an ArrayList with datetime values and use the ToArray method to create an object array. I need to use an object array becase I'm working...
2
by: Josué Maldonado | last post by:
Hi list, Is there a way to access an especific element of the array NEW in an TCL trigger, I have a loop that goes for each field (thanks Ian & Darren) like this: foreach id { then I can...
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
6
by: Steve Wasser | last post by:
I've got a DataTable, see? I'm pulling it from a stored procedure, dig? I've gotta push it to an array for calculating certain columns, then spit it to a web page. With me so far? The datacolumns...
1
by: Henri Schomäcker | last post by:
Hi folks, what I need is a kind of 2D-Array which should, in the end, represent a typical html-table and which should be sortable by column. I thought of an implementation, where an vector...
17
by: ypjofficial | last post by:
Hello All, I have read in many c++ literature that vtable is nothing but an array of pointer to virtual functions inside a class.And the class where the virtual function/s are declared stores the...
5
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is...
3
by: Joe Cool | last post by:
I am converting a VB.NET program to C#.NET. How do I code the following from VB.NET to C#.NET? Private DataTypes() As String = { "Text", "Integer", "Date" } Thanks for any help!
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.