declare array inline

  • Thread starter Thread starter Laszlo Szijarto
  • Start date Start date
L

Laszlo Szijarto

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
 
Hashtable ht = new Hashtable();
ht.Add("key",new Int32[]{3,5,6,7});

Compiles just fine for me....

HTH,

Alex
 
Hi :

You almost got it:

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

Cheers,
 
Back
Top