Solved

What does Strong Typed mean for VB.NET CollectionBase

Posted on 2006-11-24
4
434 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now