Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. VB.Net - Inheritance - can parent and child both have ToString methods? Can both be accessed / used?
  2. Public MustInherit Class MyBaseClass
  3.     Public Property Name as String
  4.  
  5.     Public Overloads Function ToString() as String
  6.         Return Name
  7.     End Function
  8. End Class
  9.        
  10. Public Class ChildClass
  11.     Inherits MyBaseClass
  12.  
  13.     Public Sub New()
  14.         Name = "This is the name"
  15.     End Sub
  16.  
  17.     public Overloads Function ToString() as string
  18.         ' Is it possible to call my base class ToString and append the text to
  19.         ' this ToString method? I realize I can simply access my Name property
  20.         ' however this does not fulfill the requirements i was given
  21.         return "Some text"
  22.     End Function
  23. End Class
  24.        
  25. dim someObject as new ChildClass("Hello VB.Net ")
  26. lblLabel.text = someObject.ToString()
  27.        
  28. public Overloads Function ToString() as string
  29.     return MyBase.ToString() + "Some text"
  30. End Function