Generic List stores Generic Class : Generic Class « Generics « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
VB.Net » Generics » Generic ClassScreenshots 
Generic List stores Generic Class
Generic List stores Generic Class

Imports System.Collections
Imports System.Collections.Generic

Public Class MainClass

   Public Shared Sub Main()
        Dim custColl As New List(Of Customer)()
        Dim cust As New Customer("1""Name")
        cust.AddItem(New Order(DateTime.Parse("10/01/2004")"1""N"))
        cust.AddItem(New Order(DateTime.Parse("10/03/2004")"2""X"))
        cust.AddItem(New Order(DateTime.Parse("10/07/2004")"3""P"))

        custColl.Add(cust)

        cust = New Customer("2""name 1")
        cust.AddItem(New Order(DateTime.Parse("11/04/2004")"6""P"))
        cust.AddItem(New Order(DateTime.Parse("11/07/2004")"8""Y"))
        cust.AddItem(New Order(DateTime.Parse("12/12/2004")"9""K"))

        custColl.Add(cust)

        cust = New Customer("3""Name 3")
        cust.AddItem(New Order(DateTime.Parse("10/01/2004")"4""W"))

        custColl.Add(cust)


        For custIdx As Int32 = To (custColl.Count - 1)
            cust = custColl(custIdx)
            Console.Out.WriteLine("Customer-) ID: {0}, Name: {1}", cust.Id, cust.Name)

            Dim orders() As Order = cust.Items
            For orderIdx As Int32 = To (orders.Length - 1)
                Dim ord As Order = orders(orderIdx)
                Console.Out.WriteLine("    Order-> Date: {0}, Item: {1}, Desc: {2}", ord.OrderDate, ord.ItemId, ord.Description)
            Next
        Next



        Dim empColl As New List(Of Employee)()
        Dim emp As New Employee("1""R")
        empColl.Add(emp)

        emp = New Employee("2""M")
        empColl.Add(emp)

        emp = New Employee("3""B")
        emp.AddItem(New Employee("6""S"))
        emp.AddItem(New Employee("7""B"))
        emp.AddItem(New Employee("8""T"))

        empColl.Add(emp)

        For mgrIdx As Int32 = To (empColl.Count - 1)
            Dim manager As Employee = empColl(mgrIdx)
            Console.Out.WriteLine("Manager-) ID: {0}, Name: {1}", manager.Id, manager.Name)

            For idx As Int32 = To (manager.Items.Length - 1)
                emp = manager.Items(idx)
                Console.Out.WriteLine("    Employee-) Id: {0}, Name: {1}", emp.Id, emp.Name)
            Next
        Next
   End Sub
End Class

Public Class Customer
    Inherits Person(Of Order)

    Public Sub New(ByVal Id As String, ByVal Name As String)
        MyBase.New(Id, Name)
    End Sub

End Class


Public Class Employee
    Inherits Person(Of Employee)

    Public Sub New(ByVal Id As String, ByVal Name As String)
        MyBase.New(Id, Name)
    End Sub

End Class


Public Class Order
    Public OrderDate As DateTime
    Public ItemId As String
    Public Description As String

    Public Sub New(ByVal OrderDate As DateTime, ByVal ItemId As String, ByVal Description As String)
        Me.OrderDate = OrderDate
        Me.ItemId = ItemId
        Me.Description = Description
    End Sub

End Class


Public Class Person(Of T)
    Public Name As String
    Public Id As String
    Private _items As List(Of T)

    Public Sub New(ByVal Id As String, ByVal Name As String)
        Me.Id = Id
        Me.Name = Name
        Me._items = New List(Of T)
    End Sub

    Public ReadOnly Property Items() As T()
        Get
            Return Me._items.ToArray()
        End Get
    End Property

    Public Sub AddItem(ByVal newItem As T)
        Me._items.Add(newItem)
    End Sub

End Class

           
       
Related examples in the same category
1. Generic Class DemoGeneric Class Demo
w___w_w_.___ja_v___a_2_s___.__co_m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.