Assuming a base type of "Message"...
Public Class Message
Public ID As Int64
Public Text As String
Public MessageType as String
End Class
...and then two derived classes...
Public Class PhoneMessage
Inherits Message
Public MessageLength As Int64
End Class
Public Class MailMessage
Inherits Message
Public Postage As Int64
End Class
I would like to have one collection of Message objects which can be either PhoneMessages or MailMessages, so that I can iterate through the list and deal with each message based on what type it happens to be.
Attempting just to use .Add() fails, saying that I can't add an item of type PhoneMessage to a List(Of Message). Is there some elegant way to accomplish what I'm trying to do? I had thought I could accomplish this with generics, but I think there's a gap in my understanding. If it can be accomplished in .NET 2.0, that would be ideal.
Thank you in advance.