//Creamos en diccionario (en Java es un HashMap)
Dictionary<int,Economica> economicas = new Dictionary<int,Economica>();
//Añadimos elementos
economicas.Add(1,new Economica(2300.09,0.15,10));
economicas.Add(2,new Economica(2700.45,0.10,10));
economicas.Add(3,new Economica(2800.09,0.13,9));
//Recorremos diccionario x Llave/Valor
foreach(var economica in economicas)
{
Console.WriteLine("{0} : {1}",economica.Key,economica.Value);
}
//Recorremos diccionario x Llave
foreach(var economica in economicas.Keys)
{
Console.WriteLine("{0}",economica);
}
//Recorremos diccionario x Valor
foreach(var economica in economicas.Value)
{
Console.WriteLine("{0}",economica);
}
Recorrer un diccionario en tres formas
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.