473,616 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5564
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.mew rote in message
news:O0******** ********@TK2MSF TNGP05.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*****@yamaga ta-europe.com" <jo*****@yamaga ta-europe.comwrote in
news:11******** **************@ q4g2000prc.goog legroups.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.mew rote:
>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
6132
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. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
7
1879
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 with various datatypes and need the code to be as generic as possible. Most of to code involves dynamically determining the datatype, which all works.
2
4296
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 refer to an element with this (inside the loop): $NEW($id)
3
14486
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 program (UNIX) as an array of "struct point" where struct point //C structure { int Time; //32 bits
6
5136
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 are dates, doubles, strings, man. How do I store all the different datatypes in a multidimensional array, dude? Am I looking at a jagged array? Nope, all answers point to another way of calulating this drek, right? I'm doing this becuase the Stored...
1
1950
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 does not keep the rows, as usual, but holds the single _columns_ as lists. In this case, every column could have it's own datatype, just like database-tables and could be sortable by the list's sort function.
17
14702
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 vfptr i.e the pointer to vtable internally. What confuses me is if vtable is an array of pointer to virtual functions then as per the properties of the array all the entries inside the array must be same.i.e all the pointers should be of similar...
5
2496
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 another way? /* * Main.java * * Created on April 29, 2007, 6:57 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
3
1717
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
8199
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8592
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7118
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6097
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2576
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 we have to send another system
1
1759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1439
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.