In addition to solution #1 by
Wendelius[
^]... you have to use
List(Of T)[
^] to manage users. For example:
First of all, MyUser class declaration:
Public Class MyUser
Private sfullName As String = String.Empty
Private sfirstName As String = String.Empty
Private slastName As String = String.Empty
Private slogin As String = String.Empty
Private iage As Byte = 0
Public Sub New(_fullName As String, _age As Integer)
sfullName = _fullName
iage = _age
FullNameToParts()
End Sub
Public Property FullName As String
Get
Return sfullName
FullNameToParts()
End Get
Set (value As String)
sfullname = value
End Set
End Property
Private Sub FullNameToParts()
Dim sParts As String() = sfullName.Split(New String(){", "}, StringSplitOptions.RemoveEmptyEntries)
If sParts.Length < 2 Then
Throw New Exception("A user's full name have to contain ', ' (comma and space)!")
Else
sfirstName = sParts(1)
slastName = sParts(0)
slogin = String.Concat(sfirstName.ToLower().Substring(0,1), slastName.ToLower())
End If
End Sub
Public Property Age As Byte
Get
Return iage
End Get
Set (value As Byte)
iage = value
End Set
End Property
Public ReadOnly Property Login As String
Get
Return slogin
End Get
End Property
End Class
Usage:
Sub Main
Dim users As List(Of MyUser) = New List(Of MyUser)
users.Add(New MyUser("Doe, John", 22))
users.Add(New MyUser("Doe, Joe", 19))
Console.WriteLine("Count of users: {0}", users.Count)
For Each mu As MyUser In users
Console.WriteLine("{0} (login: {1})", mu.FullName , mu.Login)
Next
Console.WriteLine("Average age: {0}", users.Count)
Console.WriteLine("Total age: {0}", users.Sum(Function(x) x.Age))
End Sub
Output:
Count of users: 2
Doe, John (login: jdoe)
Doe, Joe (login: jdoe)
Average age: 2
Total age: 41
This is for beginning.