static & abstract

  • Thread starter Thread starter Marty McDonald
  • Start date Start date
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?
 
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
 
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).
 
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.
 
Back
Top