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

  • Home
  • SEARCH
  • 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 6646627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:26:22+00:00 2026-05-26T00:26:22+00:00

I have a base class with one optional default parameter, which a child class

  • 0

I have a base class with one optional default parameter, which a child class automatically provides a value for:

public class Merchant
{
    public string WriteResults(List<string> moreFields = null)
    {

        List<string> ListOfObjects = new List<string>() {Name, Address};
        if (moreFields != null)
        {
            ListOfObjects.AddRange(moreFields);
        }
            return ListOfObjects.ToString() //not real output
}


public class SpecificMerchant : Merchant 
{   
    new public string WriteResults()
        {
            return ((Merchant)this).WriteResults(new List<string>() {
                    Address, Phone //class-specific parameters
            });
        }
}

I used the new keyword when calling SpecificMerchant.WriteResults because both the parent and the base can take no parameters, but the compiler says this is unnecessary:

The member ‘SpecificMerchant.WriteResults()’ does not hide an
inherited member. The new keyword is not required.

Why? Aren’t I, in practice, overriding the parent method?

  • 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-26T00:26:22+00:00Added an answer on May 26, 2026 at 12:26 am

    Because optional parameters are a compile time construct, not a runtime construct.

    Your base class is always going to have a method with one parameter. The compiler just “substitutes” null at compile time if you call that method without an argument.

    That being said, I would avoid trying to do what you’re implementing above. Even if you remove the new keyword, which will let it compile, you’re adding a lot of confusion. I would, personally, make the base class implementation virtual, if required, or add two methods to the base class and override one instead of using optional arguments.

    For a good resource, I’d recommend reading James Michael Hare’s post on Optional Parameters – He discusses the pitfalls, like this one, when you mix optional arguments with inheritance.

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

Sidebar

Related Questions

I have a base class, B, which has two constructors, one with no paremeters
In one C# project have a base class like this: public abstract class AbstractVersionedBase
I have one base class which holds a map for function pointers like this
I have a base class that has a virtual property: public virtual string Name
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have a base class object array into which I have typecasted many different
I have a base class with an optional virtual function class Base { virtual
I have a base class with a property which (the get method) I want
I have a base class and a dozen derived classes. All but one derived
I have a base class that has an enum value that I am using

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.