List in collectionbase

M

Majed

hi all
i've created a strong named collection which inherits collection base,but
when i try to add to it a nullreferenceexception blows.
the code is as listed below. do i have to init the list myself.
any hints...please!
thanks all

Public Class NewKeys

Inherits BaseCollection

Default Public Property Item(ByVal Index As Integer) As NewKey

Get

Return CType(list(Index), NewKey)

End Get

Set(ByVal Value As NewKey)

List(Index) = Value

End Set

End Property

Public Overrides ReadOnly Property Count() As Integer

Get

Return (MyBase.List.Count())

End Get

End Property

Public Function Add(ByVal value As NewKey) As Integer

Try

Return List.Add(value)

Catch e As Exception

messagebox.show(e.ToString) <------------ it blows here

debug.writeline(e.tostring())

End Try

End Function 'Add

Public Function IndexOf(ByVal value As NewKey) As Integer

Return List.IndexOf(value)

End Function 'IndexOf

Public Sub Insert(ByVal index As Integer, ByVal value As NewKey)

List.Insert(index, value)

End Sub 'Insert

Public Sub Remove(ByVal value As NewKey)

List.Remove(value)

End Sub 'Remove

Public Function Contains(ByVal value As NewKey) As Boolean

' If value is not of type newkey, this will return false.

Return List.Contains(value)

End Function

End Class
 
J

Jay B. Harlow [MVP - Outlook]

Majed,
Public Class NewKeys
Inherits BaseCollection

Have you tried inheriting from System.Collection.CollectionBase instead of
System.Windows.Forms.BaseCollection?

CollectionBase contains a List property for you ready to use, while
BaseCollection requires you to override the List property and return an
ArrayList to use.

Overall CollectionBase and other classes from System.Collection &
System.Collection.Specialized are the classes you should be using...

Hope this helps
Jay
 
M

Majed

Jay B. Harlow said:
Majed,

Have you tried inheriting from System.Collection.CollectionBase instead of
System.Windows.Forms.BaseCollection?

CollectionBase contains a List property for you ready to use, while
BaseCollection requires you to override the List property and return an
ArrayList to use.

Overall CollectionBase and other classes from System.Collection &
System.Collection.Specialized are the classes you should be using...

Hope this helps
Jay
it sure dose
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top