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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:59:56+00:00 2026-05-27T23:59:56+00:00

I was wondering about the following situation in C#. Sometimes function names can be

  • 0

I was wondering about the following situation in C#.

Sometimes function names can be quite long, and verbose. I’m using Microsoft’s MVC 3 framework for a website at work, Here’s an example function:

[ImportModelStateFromTempData]
[BreadCrumb("New Event")]
public ActionResult New()
{
    var @event = _dbContext.EventRepository.CreateNewEvent();

    return View("New", 
        EventViewModel.FromEventDomainModel(@event));
}

This code could be rewritten without use of the temporary variables @event, like so:

[ImportModelStateFromTempData]
[BreadCrumb("New Event")]
public ActionResult New()
{
    return View("New", 
        EventViewModel.FromEventDomainModel(_dbContext.EventRepository.CreateNewEvent()));
}

The first example is obviously more clear, but from a pure curiosity perspective/performance perspective, is either faster than the other? Especially considering that the cached value @event is only being used once.

In C++ I remember finding out that the local variable declaration of @event (if this were C++) would be stored in New()’s stack frame, and the assembly generated would be SLIGHTLY slower than directly in-lining the argument (as opposed to storing it in a temporary).

Is the C# compiler smarter about this situation? Am I free to use temporary’s without the same performance considerations?

I understand that pre-optimization is evil, and I absolutely should not be worried about this kind of this, but I am curious about this. I’m not even sure about where I would go looking up more information about this, as the title was the best way I could describe my question. So what do you think Stack Overflow?

  • 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-27T23:59:57+00:00Added an answer on May 27, 2026 at 11:59 pm

    The IL produced by these will be equivalent. If you want to prove it to yourself, try compiling both and looking at the resulting IL with Ildasm http://msdn.microsoft.com/en-us/library/f7dy01k1(v=vs.80).aspx

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

Sidebar

Related Questions

I was wondering about which way i should do the following. I am using
I've been wondering about the following issue: assume I have a C style function
I was wondering about the following situation: in iOS: I have viewA which goes
i was wondering about the following: i can define in IIS what to do
I'm wondering how i would go about making the following application: a user signs
Following on from my other post about primary keys I am wondering if there
I have been wondering about the reload() function in python, which seems like it
I'm playing around with WPF and databinding and I'm wondering about the following. I
I'm wondering about an algorithm solving the following (efficiently): A 2D matrix of numbers
I'm just wondering about the following 2 approaches. First: SomeViewController *someViewController = [[SomeViewController alloc]

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.