static & abstract

M

Marty McDonald

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?
 
K

Kalpesh Shah

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
 
J

Jon Skeet

Kalpesh Shah said:
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).
 
T

Tian Min Huang

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top