473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

inheritance and shared

hey 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
Nov 21 '05 #1
2 1193
"rodchar" <ro*****@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/>

Nov 21 '05 #2
thanks, this helps.

"Herfried K. Wagner [MVP]" wrote:
"rodchar" <ro*****@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/>

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
5
by: ma740988 | last post by:
Prefer composition to inheritance (can't recall which text I stole that line from) is one of the fundamental tenets thats engrained in my mind. Having said that inheritance requires careful...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
5
by: Invalidlastname | last post by:
Hi, I just read the pattern "Design and Implementation Guidelines for Web Clients" from MSDN. Here is my question. In chapter 3,...
33
by: Joe Fallon | last post by:
1. I have a Base class that has a certain amount of functionality. 2. Then I have a CodeSmith generated class that inherits from the Base class and adds functionality. 3. Since I want to be able...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
5
by: AWesner | last post by:
I've been working on a project to help myself better understand how inherited classes work. I think I've learned more about classes by doing this than any other effort I've made. I've tried to...
12
by: Massimo | last post by:
Hi to all, I'm facing a problem in a particularly complex inheritance hierarchy, and I'd like to know what the standard says about it and if my compiler is correct in what it does. I have two...
4
by: Anarki | last post by:
##include <iostream> using namespace std; class A { }; class B:virtual public A { }; class C:virtual public A
3
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.