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 876025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:21:57+00:00 2026-05-15T11:21:57+00:00

This is more or less an exact duplicate of this post , but as

  • 0

This is more or less an exact duplicate of this post, but as I cannot edit it, I started this. Feel free to move something over and close this one.

Using method hiding with new seems like a dangerous feature, and given the discussion in the other thread, it seems it’s not only I who have problems finding a valid use case for this. Any methods accepting Base won’t use Derived’s Method.

public class Base
{
    public void Method()
    {
        Console.WriteLine("Base");
    }
}

public class Derived : Base
{
    public new void Method()
    {
        Console.WriteLine("Derived");
    }
}

var derived = new Derived();
derived.Method(); // "Derived"
((Base)derived).Method(); // "Base"

So what are some valid use cases for new that is difficult to solve with other features?

  • 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-15T11:21:58+00:00Added an answer on May 15, 2026 at 11:21 am

    The idea is to avoid the brittle base class problem as far as possible.

    Suppose you provide a library, and I derive from one of your classes. I create my own method, Foo(), and call it appropriately. Fine.

    Now you introduce a second version of your library, and you add the Foo() method (with the same signature) to the base class. Now your code will call Foo(), which has one particular meaning… and that may be a completely different meaning to my Foo() method. The default behaviour (and the behaviour if you add the new modifier) is for things to behave as they should: code which only knows about the base class will call your method – which is fine, as that’s what they mean. Code which uses an expression which has a compile-time type of my derived class will use my method – and that’s fine, as that’s what they should mean as well. (Basically it can only be my code, because only my code knows about my class.)

    It should usually be avoided – it can lead to subtle bugs where changing the compile-time type of the variable silently changes the behaviour… but it’s present for that sort of situation. Basically, adding a method to a base class shouldn’t break derived classes, as far as possible.

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

Sidebar

Related Questions

I use C# code more-or-less like this to serialize an object to XML: XmlSerializer
This is more of an generic XML Schema question, but if and how do
This more or less complex phrase to translate in my Django template is: This
People generally agree that C# and VB.net are more or less the exact same
I'm writing aspect-ish code more or less lifted from the chosen solution for this
Please forgive my ignorance. Traditionally I've been doing something like this, but it feels
This is more or less an academia question to help me better understand this
I want to know this more in detail. Is it a realtime scheduler? An
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',
I am wondering if there is a way to handle this more elegantly. After

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.