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

declare array inline

Thank you in advance,

I am trying to populate a HashTable object with a value that's an array, but
I don't want to put in two lines of code for each entry.

rather than saying

int[] value = {1,2,3};
hashTable.Add("test",value);

is there any way to combine this into one line

I've tried

hashTable.Add("test",(int[]){1,2,3});
hashTable.Add("test",new int[] = {1,2,3});
hashTable.Add("test",int[] testvalue = {1,2,3};

none of these compiles. Is there any way to declare and define an array
inline?

Thank you,
Laszlo
Nov 16 '05 #1
4 2655
Hashtable ht = new Hashtable();
ht.Add("key",new Int32[]{3,5,6,7});

Compiles just fine for me....

HTH,

Alex

"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:c5*********@sulawesi-fi.lerc.nasa.gov...
Thank you in advance,

I am trying to populate a HashTable object with a value that's an array, but I don't want to put in two lines of code for each entry.

rather than saying

int[] value = {1,2,3};
hashTable.Add("test",value);

is there any way to combine this into one line

I've tried

hashTable.Add("test",(int[]){1,2,3});
hashTable.Add("test",new int[] = {1,2,3});
hashTable.Add("test",int[] testvalue = {1,2,3};

none of these compiles. Is there any way to declare and define an array
inline?

Thank you,
Laszlo

Nov 16 '05 #2
You were pretty close. Try

hashTable.Add("test",new int[]{1,2,3});

Yves

"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> schreef in bericht
news:c5*********@sulawesi-fi.lerc.nasa.gov...
Thank you in advance,

I am trying to populate a HashTable object with a value that's an array, but I don't want to put in two lines of code for each entry.

rather than saying

int[] value = {1,2,3};
hashTable.Add("test",value);

is there any way to combine this into one line

I've tried

hashTable.Add("test",(int[]){1,2,3});
hashTable.Add("test",new int[] = {1,2,3});
hashTable.Add("test",int[] testvalue = {1,2,3};

none of these compiles. Is there any way to declare and define an array
inline?

Thank you,
Laszlo

Nov 16 '05 #3
Hi :

You almost got it:

hashTable.Add("test", new int[] {1,2,3} );

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Laszlo Szijarto" <ls*******@nospam.mrdoc.cc> wrote in message
news:c5*********@sulawesi-fi.lerc.nasa.gov...
Thank you in advance,

I am trying to populate a HashTable object with a value that's an array, but I don't want to put in two lines of code for each entry.

rather than saying

int[] value = {1,2,3};
hashTable.Add("test",value);

is there any way to combine this into one line

I've tried

hashTable.Add("test",(int[]){1,2,3});
hashTable.Add("test",new int[] = {1,2,3});
hashTable.Add("test",int[] testvalue = {1,2,3};

none of these compiles. Is there any way to declare and define an array
inline?

Thank you,
Laszlo

Nov 16 '05 #4
Thank you both.
Nov 16 '05 #5

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

Similar topics

9
by: Ken | last post by:
I have a small program , wi tha menu (only option 1,2 and 6 are working for now) Something weird is happening, my array works to input all the data the user puts in, but whebn I choose option 2,...
6
by: Dylan Nicholson | last post by:
Is there any way of declaring the parameter "array" below to be const, so that the function as written will not compile: void foo(int array /*const*/) { array = array; // should not be allowed...
1
by: Sam | last post by:
Hello all I have a two dimensional array (the dimensions are not known) that needs to be passed to fortran from c++, allocate the dimensions of the array in fortran code, do some filling up of...
4
by: Laszlo Szijarto | last post by:
Thank you in advance, I am trying to populate a HashTable object with a value that's an array, but I don't want to put in two lines of code for each entry. rather than saying int value =...
4
by: thinktwice | last post by:
i have just made a test project :(win32 console) //file : func.h #ifndef _FUNC_H_ #define _FUNC_H_ void func1() { return; };
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
10
by: javuchi | last post by:
I just want to share some code with you, and have some comments and improvements if you want. This header file allocates and add and delete items of any kind of data from a very fast array: ...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
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...
12
by: mathieu | last post by:
Hi, Consider the following (*). Is there a way to rewrite it so that it remains convenient (N is being recomputed when array v is modified) *and* compiles :) Thanks, -Mathieu (*)
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.