469,295 Members | 2,056 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,295 developers. It's quick & easy.

static & abstract

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
3 3883
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
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
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.

Similar topics

3 posts views Thread by Murat Tasan | last post: by
33 posts views Thread by Chris Capel | last post: by
7 posts views Thread by Sunny | last post: by
19 posts views Thread by Mike Ruane-Torr | last post: by
4 posts views Thread by Chukkalove | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.