Advertisement
fcamuso

Collezioni - Dictionary, parte A

Nov 9th, 2021
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4.  
  5. namespace Dictionary
  6. {
  7.   class Amico
  8.   {
  9.     public String Nome { get; set; }
  10.     public String Telefono { get; set; }
  11.  
  12.     public Amico(string nome, string telefono)
  13.     { Nome = nome; Telefono = telefono; }
  14.   }
  15.  
  16.   class Gioco
  17.   {
  18.     public String Nome { get; set; }
  19.     public int etaConsigliata { get; set; }
  20.  
  21.     public Gioco(string nome, int eta)
  22.     { Nome = nome; etaConsigliata = eta; }
  23.   }
  24.  
  25.   class Program
  26.   {
  27.    
  28.     static void Main()
  29.     {
  30.       List<KeyValuePair<string, Amico>> listaAmici = new();
  31.       listaAmici.Add(new KeyValuePair<string, Amico>("Giorgio", new Amico("Giorgio", "0345-82347")));
  32.       listaAmici.Add(new KeyValuePair<string, Amico>("Massimo", new Amico("Massimo", "0345-234643")));
  33.  
  34.       Dictionary<String, Amico> amici = new(listaAmici);
  35.  
  36.       Console.WriteLine( amici.TryAdd("Giorgio", new Amico("Giorgio", "02-82347")) );
  37.  
  38.       amici["Giorgio"] = new Amico("Giorgio", "02-82347");
  39.       Console.WriteLine(amici["Giorgio"].Telefono);
  40.  
  41.       Dictionary<Gioco, Amico> abbinamenti = new();
  42.       //Gioco g = new Gioco("Tennis", 12);
  43.       abbinamenti.Add(new Gioco("Tennis", 12), amici["Massimo"]);
  44.      
  45.       Console.WriteLine(abbinamenti.ContainsKey(new Gioco("Tennis", 12)));
  46.     }
  47.   }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement