Store Structure into a Collection : Structure « Language Basics « 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
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
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » Language Basics » StructureScreenshots 
Store Structure into a Collection

Imports System
Imports System.Data
Imports System.Collections
Imports System.Windows.Forms

Public Class MainClass
    Shared Sub Main()
        Dim customers As CustomerCollection = New CustomerCollection()

        customers.Clear()
        
        Dim newCustomer As Customer
        newCustomer.FirstName = "firstName"
        newCustomer.LastName = "lastName"
        newCustomer.Email = "email"

        ' add it to the list...
        customers.Add(newCustomer)


        
    End Sub
End Class

Public Structure Customer
    Public FirstName As String
    Public LastName As String
    Public Email As String

    Public ReadOnly Property Name() As String
        Get
            Return FirstName & " " & LastName
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return Name & " (" & Email & ")"
    End Function

    Public Function IsEmpty() As Boolean
        If FirstName = "" Then
            Return True
        Else
            Return False
        End If
    End Function
End Structure

Public Class CustomerCollection
    Inherits System.Collections.CollectionBase

    Private _emailHashtable As New Hashtable()

    Public Sub Add(ByVal newCustomer As Customer)
        Me.List.Add(newCustomer)

        Dim useEmail As String
        useEmail = newCustomer.Email.ToLower
        EmailHashtable.Add(useEmail, newCustomer)

    End Sub

    Public Sub Remove(ByVal removeCustomer As Customer)
        Me.List.Remove(removeCustomer)

        Dim useEmail As String
        useEmail = removeCustomer.Email.ToLower()
        EmailHashtable.Remove(useEmail)
    End Sub

    Default Public Property Item(ByVal index As IntegerAs Customer
        Get
            Return Me.List.Item(index)
        End Get
        Set(ByVal Value As Customer)
            Me.List.Item(index= Value
        End Set
    End Property

    Public ReadOnly Property EmailHashtable() As Hashtable
        Get
            Return _emailHashtable
        End Get
    End Property


    Default Public ReadOnly Property Item(ByVal email As String_
            As Customer
        Get
            email = email.ToLower()
            Return EmailHashtable.Item(email)

        End Get
    End Property

    Public Shadows Sub Clear()
        MyBase.Clear()
        EmailHashtable.Clear()
    End Sub

    Public Shadows Sub RemoveAt(ByVal index As Integer)
        Remove(Item(index))
    End Sub
End Class

           
       
Related examples in the same category
1. Structure Variable assignment
2. ToString Method for Structure data typeToString Method for Structure data type
3. Structure overrides ToString method
4. Structure with Constructor
5. Compare Structure and ClassCompare Structure and Class
6. Pass Structure into a FunctionPass Structure into a Function
7. Simple Structure DemoSimple Structure Demo
w___w___w_._j__a_v_a2s__._c_om_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.