Initializing a HashTable like arrays

  • Thread starter Thread starter A.M-SG
  • Start date Start date
A

A.M-SG

Hi,

Considering the fact that we can initialize an two dimensional array like
the following syntax:
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };

Can I initialize a HashTable like an array?
I am trying to avoid having bunch of hashTble.Add() statements within my
constructor.

Tank you,
Alan
 
T[] ar = new T { new T(), new T(), new T() };

HashTable ht = new ht(ar);

That's the closest you could come.
What's wrong with a bunch of add calls?
 
Thank you for help.
What's wrong with a bunch of add calls?

I just like to separate data from code; however reading them from a resource
file would be too much.



KH said:
T[] ar = new T { new T(), new T(), new T() };

HashTable ht = new ht(ar);

That's the closest you could come.
What's wrong with a bunch of add calls?


A.M-SG said:
Hi,

Considering the fact that we can initialize an two dimensional array like
the following syntax:
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };

Can I initialize a HashTable like an array?
I am trying to avoid having bunch of hashTble.Add() statements within my
constructor.

Tank you,
Alan
 
A.M-SG said:
Thank you for help.


I just like to separate data from code; however reading them from a resource
file would be too much.

Well, you could always declare one array of keys and one of values,
then loop through both arrays, adding the keys appropriately.
 
Back
Top