Solved

What does Strong Typed mean for VB.NET CollectionBase

Posted on 2006-11-24
4
437 Views
Last Modified: 2012-08-13
Hi experts, I'm just wondering what does  Strong Typed mean for .NET CollectionBase Class

is it possible to hold both base and its derived class in a collectionbase?

For example, I have a base class and a class derived from the base class

public class BaseClass
    protected member1 as string

    public overridable sub mySub()
       'do something for base class
    End Sub
End Class

Public Class DerivedClass
   Inherits BaseClass
   
   Public override Sub mySub()
       'Do somthing and override mySub in base class
   End Sub
End Class

Now I define a baseclass collection

Public Class BaseClassCollection
   Inherits CollectionBase
   .....
End Class


and suppose I define an instance of BaseClassCollection

Dim myCollection as BaseClassCollection

and I put a few BaseClass objects and DerivedClass into myCollection. and suppose myCollection.Item(1) is of type DerivedClass

My question is, if I call the member function myCollection.Item(1).mySub(), is baseClass.mySub() invoked or DerivedClass.mySub() invoked?

Thanks for your help


0
Comment
Question by:caibeier
4 Comments
 
LVL 9

Accepted Solution

by:
jrscherer earned 500 total points
ID: 18013350
All depends what type you define for the Item of the BaseClassCollection. If you define it as DerivedClass then the properties of the DerivedClass will be used.
A class inherited from CollectionBase is strong typed. This means only one type can be stored, and you have to define this type through the Item property yourself.

Default Property Item(ByVal index As Integer) As DerivedClass
    Get
        Return CType(InnerList.Item(index), DerivedClass)
    End Get
    Set(ByVal Value As DerivedClass)
        InnerList.Item(index) = Value
    End Set
End Property


Jack.net
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question