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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:30:03+00:00 2026-06-12T03:30:03+00:00

I am aware that adding an optional parameter in a library method is a

  • 0

I am aware that adding an optional parameter in a library method is a breaking change,

void Foo(int x)             // OLD
void Foo(int x, int y = 5)  // NEW

because in the compiled code the new version is seen as Foo(int, int). Every call of Foo(0) (source code) is translated to Foo(0, 5) (compiled code) by the compiler. Thus, an old client, using a compiled call of Foo(0) would not find a suitable method.


What about the other direction?

void Foo(int x, int y = 5) { ... }    // OLD

void Foo(int x)        { Foo(x, 5); } // NEW
void Foo(int x, int y) { ... }        // NEW

Foo(0) (source code) would still compile, and Foo(0, 5) (compiled code) would still find a suitable overload, so, theoretically, this should work.

Does it work in practice, i.e., is this scenario “officially supported” by the .NET runtime and the C#/VB compilers? Or are calls to methods with optional parameters somehow “marked”, causing them to fail when the optional parameters are replaced by overloads?


EDIT: To clarify, I’m asking about binary compatibility: Is it possible to replace library.dll (old) with library.dll (new) without recompiling projectUsingLibrary.exe?

  • 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-06-12T03:30:04+00:00Added an answer on June 12, 2026 at 3:30 am

    I thought that was a good question, so here goes my take.

    Using a quick client that does this:

            c1.Foo(1);
            c1.Foo(1, 2);
    

    When using optional parameter the client IL looks like:

        IL_0000: nop
    IL_0001: newobj instance void [ClassLibrary1]ClassLibrary1.Class1::.ctor()
    IL_0006: stloc.0
    IL_0007: ldloc.0
    IL_0008: ldc.i4.1
    IL_0009: ldc.i4.5
    IL_000a: callvirt instance void [ClassLibrary1]ClassLibrary1.Class1::Foo(int32, int32)
    IL_000f: nop
    IL_0010: ldloc.0
    IL_0011: ldc.i4.1
    IL_0012: ldc.i4.2
    IL_0013: callvirt instance void [ClassLibrary1]ClassLibrary1.Class1::Foo(int32, int32)
    IL_0018: nop
    IL_0019: ret
    

    and when using overloads it looks like:

        IL_0000: nop
    IL_0001: newobj instance void [ClassLibrary2]ClassLibrary2.Class2::.ctor()
    IL_0006: stloc.0
    IL_0007: ldloc.0
    IL_0008: ldc.i4.1
    IL_0009: callvirt instance void [ClassLibrary2]ClassLibrary2.Class2::Foo(int32)
    IL_000e: nop
    IL_000f: ldloc.0
    IL_0010: ldc.i4.1
    IL_0011: ldc.i4.2
    IL_0012: callvirt instance void [ClassLibrary2]ClassLibrary2.Class2::Foo(int32, int32)
    IL_0017: nop
    IL_0018: ret
    

    So, if you changed the implementation from optional to overloads, but left the client as it was originally, it would be effectively adding the default parameter for you, and always calling the the function that has two arguments, which may or may not be the desired behaviour.

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

Sidebar

Related Questions

Now I'm aware that adding listeners, then setting fields would trigger the change. So
I'm aware that you can change the names of routes for devise, but I'm
So I have become aware that there is no simple way of adding a
I'm aware that in Vim I can often repeat a command by simply adding
I aware that this will be a less programming question, but still... How can
I am aware that I can set null like string val = null; But
I'm aware that this is possible with the os module's os.system(color) function, but this
I am aware that MD5 hashes are not advisable for security any more but
I am aware that I can access all external links on a page using
Now I am aware that I probably need to use a ListBox and can

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.