Sealing methods must include the override keyword, why ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Sealing methods must include the override keyword, why ?

Hybrid View

  1. #1
    Louis-Philippe Carignan Guest

    Sealing methods must include the override keyword, why ?


    Hi all,

    I was wondering why I have to put the override keyword when I want to seal
    a method. Sealing a class is pretty easy because you put the sealed keyword
    in front of the class. But for functions, the C# compiler tells me that
    I have to add the keyword override. Is that normal ?

    For example,

    public sealed void foo() {}; // Won't compile

    public sealed override foo() {} // No problem

    Thanks,

    Louis-Philippe

  2. #2
    Miha Markic Guest

    Re: Sealing methods must include the override keyword, why ?

    IMO you have no need to seal a non-virtual method.

    --
    Miha

    "Louis-Philippe Carignan" <lpcarignan@signaflex.qc.ca> wrote in message
    news:3c6d4c72$1@10.1.10.29...
    >
    > Hi all,
    >
    > I was wondering why I have to put the override keyword when I want to seal
    > a method. Sealing a class is pretty easy because you put the sealed

    keyword
    > in front of the class. But for functions, the C# compiler tells me that
    > I have to add the keyword override. Is that normal ?
    >
    > For example,
    >
    > public sealed void foo() {}; // Won't compile
    >
    > public sealed override foo() {} // No problem
    >
    > Thanks,
    >
    > Louis-Philippe




  3. #3
    Jay B. Harlow Guest

    Re: Sealing methods must include the override keyword, why ?

    Louis-Philippe,
    Sealing a method implies that the method was previously overridable, hence
    the need for override.

    If the method is not currently overridable, it is already "sealed", as Miha
    has stated. So you would not really need either...

    Hope this helps
    Jay

    "Louis-Philippe Carignan" <lpcarignan@signaflex.qc.ca> wrote in message
    news:3c6d4c72$1@10.1.10.29...
    >
    > Hi all,
    >
    > I was wondering why I have to put the override keyword when I want to seal
    > a method. Sealing a class is pretty easy because you put the sealed

    keyword
    > in front of the class. But for functions, the C# compiler tells me that
    > I have to add the keyword override. Is that normal ?
    >
    > For example,
    >
    > public sealed void foo() {}; // Won't compile
    >
    > public sealed override foo() {} // No problem
    >
    > Thanks,
    >
    > Louis-Philippe




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center