473,414 Members | 1,596 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,414 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 35676
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: 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:
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
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...
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...
0
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,...

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.