Dim DicPessoas As New Dictionary(Of String, Pessoa)
Public
Class Form1
Dim pessoaTeste As
Pessoa
Dim DicPessoas As
New Dictionary(Of
String, Pessoa)
Dim NPessoas As
Integer = 0
Private Sub
Pessoa2ListBox(ByVal chave
As String)
Me.ListBoxCod.Items.Add(DicPessoas(chave).Codigo)
Me.ListBoxNome.Items.Add(DicPessoas(chave).Nome)
Me.ListBoxDataN.Items.Add(DicPessoas(chave).DataNascimento)
Me.ListBoxIdade.Items.Add(DicPessoas(chave).Idade)
TextBoxDictionaryCount.Text = DicPessoas.Count
End Sub
Private Sub
Button3_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Button3.Click
pessoaTeste = New Pessoa(Me.TextBox4.Text,
Me.TextBox5.Text,
CType(Me.TextBox6.Text,
Date))
DicPessoas.Add(Me.TextBox4.Text,
pessoaTeste)
Pessoa2ListBox(Me.TextBox4.Text)
End Sub
Private Sub
Button4_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles ButtonLimpar.Click
Me.ListBoxCod.Items.Clear()
Me.ListBoxNome.Items.Clear()
Me.ListBoxDataN.Items.Clear()
Me.ListBoxIdade.Items.Clear()
End Sub
Private Sub
Button5_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Button5.Click
Pessoa2ListBox(Me.TextBox7.Text)
End Sub
Private Sub
Button6_Click(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles Button6.Click
For Each
estranho As KeyValuePair(Of
String, Pessoa) In
DicPessoas
Pessoa2ListBox(estranho.Key)
Next
End Sub
End
Class
Public
Class Pessoa
Private L_Codigo As
String = ""
Private L_Nome As
String = ""
Private L_DataNasc As
Date = Nothing
Public Sub
New()
End Sub
Public Sub
New(ByVal
Codigo As String)
L_Codigo = Codigo
End Sub
Public Sub
New(ByVal
Codigo As String,
ByVal nome As
String)
L_Codigo = Codigo
L_Nome = nome
End Sub
Public Sub
New(ByVal
Codigo As String,
ByVal nome As
String, ByVal
DataNasc As Date)
L_Codigo = Codigo
L_Nome = nome
L_DataNasc = DataNasc
End Sub
Public Property
Codigo() As String
Get
Return L_Codigo
End Get
Set(ByVal
value As String)
L_Codigo = value
End Set
End Property
Public Property
Nome() As String
Get
Return L_Nome
End Get
Set(ByVal
value As String)
L_Nome = value
End Set
End Property
Public Property
DataNascimento() As
Date
Get
Return L_DataNasc
End Get
Set(ByVal
value As Date)
L_DataNasc = value
End Set
End Property
Public ReadOnly
Property Idade() As
Integer
Get
Return DateDiff(DateInterval.Year,
L_DataNasc, Today)
End Get
End Property
End
Class