By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,657 Members | 1,539 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,657 IT Pros & Developers. It's quick & easy.

static & abstract

P: n/a
protected abstract static string SetConnectionToUse(DataMode whatMode);
This is illegal to the C# compiler, because "static" & "abstract" don't go
together. But how else can one force deriving classes to implement a method
while still making the method static?
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can define an interface in which you define the method

static string SetConnectionToUse(DataMode whatMode)
{
}

& let the new class implement the interface, hence the class implementing
the above interface will have to provide for this method

HTH
Kalpesh

"Marty McDonald" <mc******@wsdot.wa.gov> wrote in message
news:#z**************@TK2MSFTNGP10.phx.gbl...
protected abstract static string SetConnectionToUse(DataMode whatMode);
This is illegal to the C# compiler, because "static" & "abstract" don't go
together. But how else can one force deriving classes to implement a method while still making the method static?

Nov 13 '05 #2

P: n/a
Kalpesh Shah <sh*********@hotmail.com> wrote:
You can define an interface in which you define the method

static string SetConnectionToUse(DataMode whatMode)
{
}

& let the new class implement the interface, hence the class implementing
the above interface will have to provide for this method


No you can't. Interfaces can't define static methods - and if they
could, you wouldn't specify it in the above form (with an empty but
present method body).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #3

P: n/a
Hi Marty,

Based on my experience and research, I did not find a method to work around
this problem.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! C www.microsoft.com/security
This posting is provided as is with no warranties and confers no rights.
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.