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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:14:18+00:00 2026-06-01T17:14:18+00:00

Suppose I have some code like this: public string SomeMethod(int Parameter) { string TheString

  • 0

Suppose I have some code like this:

public string SomeMethod(int Parameter)
{
  string TheString = "";

  TheString = SomeOtherMethod(Parameter);

  return TheString;
}

Of course, this code is equivalent to this:

public string SomeMethod(int Parameter)
{
  return SomeOtherMethod(Parameter);
}

I think the first version is more readable and that’s how I’m writing my code, even thought I’m using a variable when I know I could avoid it.
My question is this: does the compiler compile the code in the same way (ie same performance) or is the second option really better in terms of performance.

Thanks.

  • 1 1 Answer
  • 2 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-01T17:14:19+00:00Added an answer on June 1, 2026 at 5:14 pm

    I’d say the first form is less readable and it contains a redundant initializer. Why initialize the variable to “” if you’re about to give it a different value? At least change it to:

    public string SomeMethod(int parameter)
    {
      string returnValue = SomeOtherMethod(parameter);    
      return returnValue;
    }
    

    or if you really want to separate declaration from initialization:

    public string SomeMethod(int parameter)
    {
      string returnValue;
      returnValue = SomeOtherMethod(parameter);    
      return returnValue;
    }
    

    (Note that I’ve also adjusted the named to follow .NET naming conventions and to give a more meaningful name to the local variable -“TheString” conveys no useful meaning.)

    You really won’t see any performance problems from using the local variable, but I’d really encourage you to think about the readability. What is the purpose of the local variable here? You’d presumably describe the method as: “Returns the result of calling SomeOtherMethod with the given parameter” – at which point, the one-line version implements exactly that description.

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

Sidebar

Related Questions

Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have the following code: foreach(string str in someObj.GetMyStrings()) { // do some
Suppose, I have saved some permissions in the database by using this code: RoleRepository
suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
I have a Java method something like this public boolean ReadBool(String ValueName, Boolean Value)
I have some not understanding actions from gnu clisp Suppose, I have some code
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
Assumptions Suppose I have a class with a property: class ClassWithProperty { public string
Suppose a construct like this: class Interface { public: template <typename T> virtual void
For example, suppose I have a class: class Foo { public: std::string& Name() {

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.