VB.Net Tutorial/Generics/Generic List — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:40, 26 мая 2010
Generic list of user objects
Imports System.Collections.Generic
public class Test
public Shared Sub Main
Dim emp_list As New EmployeeList
emp_list.Add(New Employee("G", "M"))
emp_list.Add("Z", "M")
End Sub
End class
Public Class Employee
Private m_FirstName As String
Private m_LastName As String
Public Sub New(ByVal first_name As String, ByVal last_name As String)
m_FirstName = first_name
m_LastName = last_name
End Sub
Public Overrides Function ToString() As String
Return m_FirstName & " " & m_LastName
End Function
End Class
Public Class EmployeeList
Inherits List(Of Employee)
Public Overloads Sub Add(ByVal first_name As String, ByVal last_name As String)
Dim emp As New Employee(first_name, last_name)
MyBase.Add(emp)
End Sub
End Class
Use generic List
Imports System.Collections.Generic
public class Test
public Shared Sub Main
Dim places As New List(Of String)
places.Add("A")
places.Add("B")
places.Add("C")
places.Add("D")
End Sub
End class