Results 1 to 3 of 3

Thread: Removing class collection object?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    47

    Removing class collection object?

    Hi. I've written my own class that inherits the CollectionBase class which i named it the ObjectCollection class. I implement this class as a type-safe collection that only permits the addition/removal of a custom class that i've written myself.
    For eg.

    Code:
    Public Class Student 
        Name As String 
        Age As Integer 
        Address As String 
        DateOfBirth As Date 
    End Class 
    
    Public Class ObjectCollection 
        Inherits CollectionBase 
    
        Public Function Add(ByVal Obj As Student) As Integer 
            Return innerlist.Add(Obj) 
        End Function 
    
        Public Sub Remove(ByVal Obj As Student) 
            innerlist.Remove(Obj) 
        End Sub 
    
        Default Public Property Item(ByVal Index As Integer) As Student 
            Get 
                Return DirectCast(innerlist.Item(Index), Student) 
            End Get 
            Set(ByVal Value As Student) 
                innerlist.Item(Index) = Value 
            End Set 
        End Property 
    End Class
    I would like to implement a Dispose method that removes all Student object from the ObjectCollection class. How do i do that?

    Thanks,
    Archaven

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You have to implement IDisposable. Check on MSDN. MS has an article on implementing a dispose method.

  3. #3
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Why couldn't you just do:
    VB Code:
    1. Me.List.Clear()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width