static & abstract

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marty McDonald

    #1

    static & abstract

    protected abstract static string SetConnectionTo Use(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?


  • Kalpesh Shah

    #2
    Re: static & abstract

    You can define an interface in which you define the method

    static string SetConnectionTo Use(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" <mcdonama@wsdot .wa.gov> wrote in message
    news:#zPUhUlSDH A.1556@TK2MSFTN GP10.phx.gbl...[color=blue]
    > protected abstract static string SetConnectionTo Use(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[/color]
    method[color=blue]
    > while still making the method static?
    >
    >[/color]


    Comment

    • Jon Skeet

      #3
      Re: static &amp; abstract

      Kalpesh Shah <shahkalpesh@ho tmail.com> wrote:[color=blue]
      > You can define an interface in which you define the method
      >
      > static string SetConnectionTo Use(DataMode whatMode)
      > {
      > }
      >
      > & let the new class implement the interface, hence the class implementing
      > the above interface will have to provide for this method[/color]

      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 - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Tian Min Huang

        #4
        RE: static &amp; abstract

        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.


        Comment

        Working...