Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 830287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:01:14+00:00 2026-05-15T04:01:14+00:00

Often, in C# documentation, you come across a member where the description says something

  • 0

Often, in C# documentation, you come across a member where the description says something along the lines of “be sure to call the base method if you override this.”

Is there a way to ensure at compile time that one has actually called the base function?

Here’s an example:
Implementing a Dispose Method

From the first lines:

A type’s Dispose method should release
all the resources that it owns. It
should also release all resources
owned by its base types by calling its
parent type’s Dispose method.

EDIT

I was browsing, and I came across this article, which seems rather relevant. It’s more of a small than an error, ie. it has valid uses (such as those mentioned):

Call Super

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:01:15+00:00Added an answer on May 15, 2026 at 4:01 am

    You can’t enforce it, but you can do it via a call like base.Foo(bar). base allows you to access members of the class you’re inheriting from.

    You can kind of enforce this behavior by using the template method pattern. For example, imagine you had this code:

    abstract class Animal
    {
        public virtual void Speak()
        {
            Console.WriteLine("I'm an animal.");
        }
    }
    
    class Dog : Animal
    {
        public override void Speak()
        {
            base.Speak();
            Console.WriteLine("I'm a dog.");
        }
    }
    

    The trouble here is that any class inheriting from Animal needs to call base.Speak(); to ensure the base behavior is executed. You can automatically enforce this by taking the following (slightly different) approach:

    abstract class Animal
    {
        public void Speak()
        {
            Console.WriteLine("I'm an animal.");
            DoSpeak();
        }
    
        protected abstract void DoSpeak();
    }
    
    class Dog : Animal
    {
        protected override void DoSpeak()
        {
            Console.WriteLine("I'm a dog.");
        }
    }
    

    In this case, clients still only see the polymorphic Speak method, but the Animal.Speak behavior is guaranteed to execute. The problem is that if you have further inheritence (e.g. class Dachsund : Dog), you have to create yet another abstract method if you want Dog.Speak to be guaranteed to execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apple uses modal often in their documentation. Like dismissModalViewController in their titles of methods,
I've noticed that the domain contoso.com is often used in documentation when a sample
Do you often see in API documentation (as in 'javadoc of public functions' for
An often overlooked function that requires no external library, but basically has no documentation
One problem I have with open-source is not often the product or documentation, but
I see this quiet often in C# documentation. But what does it do? public
since i can't find much documentation on HQL, what I often do it look
We archive documentation for every release, but the top google result is often several
The documentation on contenttypes says this: If you know which models you'll be using
I often want to look up items in the documentation that are not in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.