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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:53:47+00:00 2026-05-22T16:53:47+00:00

Since C# added optional parameters is it considered a better practice to use optional

  • 0

Since C# added optional parameters is it considered a better practice to use optional parameters or method overloads or is there a particular case where you would want to use one over the other. i.e a function w/ lots of parameters would be better suited w/ optional parameters?

  • 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-22T16:53:48+00:00Added an answer on May 22, 2026 at 4:53 pm

    Optional parameters are nice, but should be used when it makes sense. Optional parameters often muddy the intent of the method — If there is another alternative I would lean towards the alternative.

    Part of the need for optional parameters and named parameters is because COM allowed optional and name parameters:

    MSDN

    Some APIs, most notably COM interfaces
    such as the Office automation APIs,
    are written specifically with named
    and optional parameters in mind. Up
    until now it has been very painful to
    call into these APIs from C#, with
    sometimes as many as thirty arguments
    having to be explicitly passed, most
    of which have reasonable default
    values and could be omitted.

    SomeNewKid from forums.asp.net puts succinctly:

    http://forums.asp.net/t/386604.aspx/1

    …overloaded methods are generally
    preferable to optional parameters.
    Why? To keep each of your methods
    clear in purpose. That is, each method
    should do one thing well. As soon as
    you introduce optional parameters, you
    are diluting the cleanliness of that
    method, and introducing branching
    logic that is probably best kept out
    of a method. This clarity of purpose
    becomes even more important when you
    start using inheritance. If you
    override a method that has one or more
    optional parameters, they become
    harder to work with. So, I’d suggest
    that for anything other than quick and
    dirty classes, you use overloading in
    preference to optional parameters.

    Keep in mind that optional parameters are a syntactical sugar:

    Reflector C#:

    public class Class1
    {
        // Methods
        public Class1()
        {
            this.Method1("3", "23");
        }
    
        public void Method1(string one, [Optional, DefaultParameterValue("23")] string two)
        {
        }
    }
    

    IL:

    .class public auto ansi beforefieldinit Class1
        extends [mscorlib]System.Object
    {
        .method public hidebysig specialname rtspecialname instance void .ctor() cil managed
        {
            .maxstack 8
            L_0000: ldarg.0 
            L_0001: call instance void [mscorlib]System.Object::.ctor()
            L_0006: nop 
            L_0007: nop 
            L_0008: ldarg.0 
            L_0009: ldstr "3"
            L_000e: ldstr "23"
            L_0013: call instance void WebApplication1.Class1::Method1(string, string)
            L_0018: nop 
            L_0019: nop 
            L_001a: ret 
        }
    
        .method public hidebysig instance void Method1(string one, [opt] string two) cil managed
        {
            .param [2] = string('23')
            .maxstack 8
            L_0000: nop 
            L_0001: ret 
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the snapshot of the query that doesn't work since I added the
Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better,
Since CS3 doesn't have a web service component, as previous versions had, is there
Since debate without meaningful terms is meaningless , I figured I would point at
Since the keyboard is the interface we use to the computer, I've always thought
Since Rails is not multithreaded (yet), it seems like a threaded web framework would
Since I added some scrollTop -animation, some parts of my callback get called twice:
Im awful at multithreadding but ever since I added the following line to my
Ever since I added a new Class to my Android app (specifically, a sqlite
I have a huge amount of elements in my website... And since I added

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.