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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:00:12+00:00 2026-05-15T07:00:12+00:00

C#4.0 introduced a very fancy and useful thing by allowing default parameters in methods.

  • 0

C#4.0 introduced a very fancy and useful thing by allowing default parameters in methods. But C#3.0 doesn’t. So if I want to simulate “default parameters”, I have to create two of that method, one with those arguments and one without those arguments. There are two ways I could do this.

Version A – Call the other method

public string CutBetween(string str, string left, string right, bool inclusive)
{
    return str.CutAfter(left, inclusive).CutBefore(right, inclusive);
}

public string CutBetween(string str, string left, string right)
{
    return CutBetween(str, left, right, false);
}

Version B – Copy the method body

public string CutBetween(string str, string left, string right, bool inclusive)
{
    return str.CutAfter(left, inclusive).CutBefore(right, inclusive);
}

public string CutBetween(string str, string left, string right)
{
    return str.CutAfter(left, false).CutBefore(right, false);
}

Is there any real difference between these? This isn’t a question about optimization or resource usage or anything (though part of it is my general goal of remaining consistent), I don’t even think there is any significant effect in picking one method or the other, but I find it wiser to ask about these things than perchance faultily assume.

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

    The only real difference is that of maintenance; the second version is essentially a form of code duplication and you’ll have more work to do (and perhaps more tests to run) if you need to change the implementation of these.

    Otherwise, they’re basically the same in every other respect – you’ll have one extra method on the call stack in the first case, which won’t have any noticeable effect on performance or resource usage (as you said, not an optimization problem).

    Given that, when I need several overloads of the same method I tend to do what you did in the first example – have several overloaded methods all call the same “general” method.

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

Sidebar

Related Questions

I'm very happy that Lion introduced NSRegularExpression , but I can't understand why the
With Rails 3.1, the sprockets gem was introduced. I have written a very large
Courses for people who are being introduced to programming very often include a code
I'm from a Windows programming background when writing tools, but have been programming using
I have implemented lucene for my application and it works very well unless you
I have results from a survey. I am trying to create a graphic displaying
Since Safari 5 introduced the Reader feature, the RSS button has become very inaccessible
i have just been introduced to simulated annealing and would like to understand it
We are a Microsoft shop, have a reasonably mature technology stack and have very
I have a website which I have been working on creating very rapidly, and

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.