C#: HashTable Genérico
Achei estranho não existir a coleção genérica HashTable. Porém, existe uma equivalente: Dictionary<TKey, TValue>.
Para usá-la é o mesmo estilo da HashTable:
Dictionary<string, int> lista = new Dictionary<string, int>(); lista.Add("numero1", 1); lista.Add("numero2", 2); foreach (KeyValuePair<string, int> item in lista) { Console.Write("Key = " + item.Key + " - Value = " + item.Value); }
É isso ae. Até +.




Marco,
Tem HashTable sim!
Mas é necessário adicionar o
using System.Collections;
E não é necessário dizer que é de ’string’ e ‘int’
Exemplo:
———–
Hashtable meuHash = new Hashtable();
meuHash.Add( “numero1″, 1);
meuHash.Add( “numero2″, 2);
[]´s
Cristina
Cristina,
Mas essa sua solução utiliza o HashTable não-genérico. Veja no método Add que ele recebe objects.
T+.