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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:45:05+00:00 2026-06-09T17:45:05+00:00

So I have read this article C# Overloads which says that you can use

  • 0

So I have read this article C# Overloads which says that you can use overloaded methods to eliminate complexity and enhance performance and they provide the following example:

using System;

class Program
{
    public static void Main()
    {
    ShowString(string.Empty);
    ShowString("Category");
    }

    static void ShowString(string value)
    {
    if (value == string.Empty)
    {
        Console.WriteLine("Popular");
    }
    else
    {
        Console.WriteLine(value);
    }
    }
}

which they then rewrite using overloads:

using System;

class Program
{
    public static void Main()
    {
    ShowString();
    ShowString("Category");
    }

    static void ShowString()
    {
    // Send default argument to overload.
    ShowString("Popular");
    }

    static void ShowString(string value)
    {
    // We don't need an if check here, which makes
    // ... calling this method directly faster.
    Console.WriteLine(value);
    }
}

Would using the overloads variant provide better performance results than using a method with a default parameter value?

like:

using System;

class Program
{
    public static void Main()
    {
    ShowString();
    ShowString("Category");
    }

    static void ShowString(string value = "Popular")
    {
    // We don't need an if check here, which makes
    // ... calling this method directly faster.
    Console.WriteLine(value);
    }
}

or is the last block of code the equivalent of the first block of code?

  • 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-09T17:45:06+00:00Added an answer on June 9, 2026 at 5:45 pm

    No, default parameters are at least as fast as overloads, because your last example compiles to:

    ....
    ShowString("Popular");
    ShowString("Category");
    ....
    

    Your second example (using overloads) would (if built for Release instead of Debug) likely be inlined at runtime so that the performance would be the same as the last example (default parameters).

    The example is kind of silly, since the cost of value == string.Empty is practically nothing, but I suppose it serves to illustrate the point. However, and this is probably the most important bit you should take from this answer: You should always go for clearer/more maintainable code before premature optimization, so usability should be the overriding factor in determining what you should use in a given situation.

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

Sidebar

Related Questions

I have read from this article http://codahale.com/how-to-safely-store-a-password/ and it says using a salt isn't
I've read this article , which describes how instance vs static methods get called
i have read this article ScuttGu for making use of User control to make
i have read this article from dev.mysql . in that page is a example
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is
First let me say I have read this useful article thoroughly and am using
I have previously read Spolsky's article on character-encoding, as well as this from dive
I have read many article about this one. I want to hear from you.
I have read this article about using WMI to change the settings of NICs

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.