I need to create an array that contains n hashtable () objects or that contains n objects. I do not know how to declare this array or arrayList in C # (VS2008)
Hashtable myHT = new Hashtable();
Array myArray = // ¿ Como declararlo ?
I need to create an array that contains n hashtable () objects or that contains n objects. I do not know how to declare this array or arrayList in C # (VS2008)
Hashtable myHT = new Hashtable();
Array myArray = // ¿ Como declararlo ?
To work with arrays, you should do it in the following way
//Defino un array de Hastable con 10 posiciones
Hashtable[] array = new Hashtable[10];
//Lo recorro e inicializo cada objeto dentro dle array
for(int i = 0;i < array.Length ; i++)
{
array[i] = new Hashtable();
}
And you can work with your array of Hashtable
, however, if you do not have very specific requirements, it would be better to work with List<T>
since it is much more practical.
An example would be
List<Hashtable> Lista = new List<Hashtable>();
Hashtable hashTable = new Hashtable();
//Trabajas con el objeto y luego podes añadirlo a la lista, sin necesidad de definir un tamaño
Lista.add(hashTable);
Edit
If you're looking to use an Array instead of a list (and you do not know what size it will be), you can do the following
//Definis una lista
List<Hashtable> Lista = new List<Hashtable>();
Hashtable hashTable = new Hashtable();
//La llenas según necesidad
Lista.add(hashTable);
//Definis el array le asignas la lista utilizando ToArray()
Hashtable[] hashTableArray = Lista.ToArray();