1 Replies - 691 Views - Last Post: 01 February 2012 - 01:58 PM Rate Topic: -----

#1 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 75
  • View blog
  • Posts: 323
  • Joined: 12-January 11

Question on inheritance

Posted 31 January 2012 - 05:16 PM

I remember the very basics of inheritance from my C++ and Java classes from school, but this basic knowledge is not enough for my current problem.

Basically, I have a parent class called "Roll" and I have two child classes that inherit from it, lets call them "type1" and "type2". Now, according to what I remember from the inheritance idea is that the child classes have an "is a" relationship to the parent (i.e. type1 is a roll, type2 is a roll). What I am trying to do is determine whether the specific instance is a type1 or a type2 and return the correct version. Something like this (although I already know this doesnt work):
Private Function GetInfo(Byval id as String) as Roll
     Dim type as Integer = GetTheType(id)

     If type = 1 then
          GetInfo = New Type1(id)
     ElseIf type = 2 then
          GetInfo = New Type2(id)
     Else 'the id doesnt exist
          GetInfo = Nothing
End Function



Thats the basic idea. Any help would be much appreciated.

EDIT: Holy Christ I'm an idiot...that code does work, I just forgot to add the Inherits part of the code when creating all my classes /facepalm

This post has been edited by Psyguy: 31 January 2012 - 05:17 PM


Is This A Good Question/Topic? 2
  • +

Replies To: Question on inheritance

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,189
  • Joined: 02-June 10

Re: Question on inheritance

Posted 01 February 2012 - 01:58 PM

Doesn't VB.NET support the same .NET functionality of GetType() we use in C#?

http://msdn.microsof...s(v=vs.71).aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1