Advertisement
NelloRizzo

Collections

Apr 24th, 2020
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.38 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Sub Consumatore(c As IEnumerable)
  4.         Console.WriteLine("Consumo con IEnumerable")
  5.         Dim enumerator As IEnumerator = c.GetEnumerator
  6.         While enumerator.MoveNext()
  7.             Console.WriteLine(enumerator.Current)
  8.         End While
  9.         Console.WriteLine("------")
  10.     End Sub
  11.     Sub Main()
  12.         Dim codaStringhe As New Queue(Of String) ' coda: gestione FIFO
  13.         codaStringhe.Enqueue("Uno") ' accodamento
  14.         codaStringhe.Enqueue("Due")
  15.         codaStringhe.Enqueue("Tre")
  16.         'Console.WriteLine(codaStringhe.Dequeue()) ' consumo
  17.         'Console.WriteLine(codaStringhe.Dequeue()) ' consumo
  18.         'Console.WriteLine(codaStringhe.Dequeue()) ' consumo
  19.         Console.WriteLine("Consumo di coda:")
  20.         For Each item In codaStringhe
  21.             Console.WriteLine(item)
  22.         Next
  23.  
  24.         Console.WriteLine("-----")
  25.         Dim pilaStringhe As New Stack(Of String) ' stack o pila: gestione LIFO
  26.         pilaStringhe.Push("Uno") ' accodamento
  27.         pilaStringhe.Push("Due") ' accodamento
  28.         pilaStringhe.Push("Tre") ' accodamento
  29.         'Console.WriteLine(pilaStringhe.Pop()) ' consumo
  30.         'Console.WriteLine(pilaStringhe.Pop()) ' consumo
  31.         'Console.WriteLine(pilaStringhe.Pop()) ' consumo
  32.         Console.WriteLine("Consumo di stack:")
  33.         For Each item In pilaStringhe
  34.             Console.WriteLine(item)
  35.         Next
  36.         Console.WriteLine("-----")
  37.  
  38.         Dim listaStringhe As New List(Of String) ' lista
  39.         listaStringhe.Add("Uno") ' accodamento
  40.         listaStringhe.Add("Tre")
  41.         listaStringhe.Insert(1, "Due") 'inserimento
  42.         Console.WriteLine(listaStringhe(0)) 'consumo
  43.         Console.WriteLine(listaStringhe(1))
  44.         Console.WriteLine(listaStringhe(2))
  45.         Consumatore(listaStringhe)
  46.         Dim hs As New HashSet(Of String) ' lista senza duplicati
  47.         hs.Add("Uno") ' accodamento
  48.         hs.Add("Tre")
  49.         hs.Add("Due")
  50.         hs.Add("Uno")
  51.         For Each item In hs
  52.             Console.WriteLine(item)
  53.         Next
  54.         Consumatore(hs)
  55.  
  56.         Dim dis As New Dictionary(Of Integer, String)
  57.         dis.Add(1, "Uno")
  58.         dis.Add(2, "Due")
  59.         dis.Add(3, "Tre")
  60.         Console.WriteLine(dis(3))
  61.  
  62.         Dim dsi As New Dictionary(Of String, Integer)
  63.         dsi.Add("Pimo", 1)
  64.         dsi.Add("Secondo", 2)
  65.         dsi.Add("Terzo", 3)
  66.         Console.WriteLine(dsi("Secondo"))
  67.     End Sub
  68.  
  69. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement