|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
inheritance and sharedhey all,
i have a MustInherit class and a derived class. is it possible to have a shared method in the base class and use it? Note: this is not working for me but just going to explain. i have a base class that has a shared function that returns a connection string for a datasource. is there a way for the derived class to use that? when i try me.connStr it says i have to instantiate it. thanks, rodchar "rodchar" <rodc***@discussions.microsoft.com> schrieb: Shared methods are not "virtual" and not bound to an instance of a class. > i have a MustInherit class and a derived class. is it possible to have a > shared method in the base class and use it? > > Note: this is not working for me but just going to explain. > > i have a base class that has a shared function that returns a connection > string for a datasource. is there a way for the derived class to use that? > when i try me.connStr it says i have to instantiate it. Nevertheless you can access them using a variable that is pointing to an instance of the type or one of its derived types. Typically shared methods are qualified with the class name of the class they are defined in: \\\ Public MustInherit Class Bar Private Shared m_UserName As String = "John Doe" Public Shared Function GetUserName() As String Return m_UserName End Function End Class Public Class FooBar Inherits Bar Public Sub New() MsgBox(Bar.GetUserName()) End Sub End Class /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> thanks, this helps.
Show quoteHide quote "Herfried K. Wagner [MVP]" wrote: > "rodchar" <rodc***@discussions.microsoft.com> schrieb: > > i have a MustInherit class and a derived class. is it possible to have a > > shared method in the base class and use it? > > > > Note: this is not working for me but just going to explain. > > > > i have a base class that has a shared function that returns a connection > > string for a datasource. is there a way for the derived class to use that? > > when i try me.connStr it says i have to instantiate it. > > Shared methods are not "virtual" and not bound to an instance of a class. > Nevertheless you can access them using a variable that is pointing to an > instance of the type or one of its derived types. Typically shared methods > are qualified with the class name of the class they are defined in: > > \\\ > Public MustInherit Class Bar > Private Shared m_UserName As String = "John Doe" > > Public Shared Function GetUserName() As String > Return m_UserName > End Function > End Class > > Public Class FooBar > Inherits Bar > > Public Sub New() > MsgBox(Bar.GetUserName()) > End Sub > End Class > /// > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > >
How to Print PRN file
InStr Time Critical Process in .NET Converting MS Access 2000 application to a VB / VB.NET application looking for CPU-specific developer's benchmarking How to Prevent Flicker when Updating ListView Form that slides up into view (MSN Style) AddHandler RemoveHandler Question date problem in datagrid List View question |
|||||||||||||||||||||||