[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

What does Strong Typed mean for VB.NET CollectionBase

Posted on 2006-11-24
4
Medium Priority
?
442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Accepted Solution

by:
jrscherer earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

650 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