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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:28:08+00:00 2026-05-14T08:28:08+00:00

One question regarding whether the following code should yield a compiler warning or not

  • 0

One question regarding whether the following code should yield a compiler warning or not (it doesn’t). It declares two methods of the same name/return type, one has an additional named/optional parameter with default value.

NOTE: technically the resolution isn’t ambiguous, because the rules clearly state that the first method will get called. See here, Overload resolution, third bullet point. This behavior is also intuitive to me, no question.

public void Foo(int arg) { ... }

public void Foo(int arg, bool bar = true) { ...} 

Foo(42); // shouldn't this give a compiler warning?

I think a compiler warning would be kind of intuitive here. Though the code technically is clean (whether it is a sound design is a different question:)).

  • 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-14T08:28:09+00:00Added an answer on May 14, 2026 at 8:28 am

    I disagree that it needs a warning, actually. The main issue is, that code is potentially legitimate, and if that’s the case you would have to explicitly disable the warning.

    What I mean is, in general when you get a warning, you will be able to change your code to get rid of the warning (and presumably make the code better at the same time). But in this case, it may be that you did it like that intentionally and would not be able to change your code to get rid of the warning.

    For example, the “unreachable code” warning is something you can just delete the unreachable code to get rid of the warning. Or the “could not find reference” warning – this is usually a signal that you’re going to get “undefined type” errors, but if not then you can simply delete the reference. Or maybe “A previous catch clause already catches all exceptions” warning: in this case, you need to change your code so that either the new clause comes before the catch-all, or remove the catch altogether.

    But the point is that in every case when you get a warning, you should change your code, and making the change will always result in “better” code. However, in the case of this question, the call is not ambiguous (as far as the compiler is concerned) and I don’t think you can argue that it’s always a mistake to write code like that, so therefore there shouldn’t be a warning.

    If the compiler issued a warning about every case where you do something that’s probably not the best idea, then we’d be inundated with warnings!

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

Sidebar

Related Questions

I have a question about best practices regarding how one should approach storing complex
I was reading a question about c# code optimization and one solution was to
I have two String.printable mysteries in the one question. First, in Python 2.6: >>>
I have question regarding the CreateWindowEx function. I have 2 windows, a main one
After posting this question and reading that one I realized that it is very
I just finished a test as part of a job interview, and one question
I am looking into Cloud Computing for my company. The one question that I
I got one big question. I got a linq query to put it simply
After considering the answers to my previous question ( One SVN Repository or many?
Surprisingly I was only able to find one previous question on SO about this

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.