473,396 Members | 1,743 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,396 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 35675
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...
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: 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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.