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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:01:01+00:00 2026-05-27T16:01:01+00:00

Often we’re told things like, If you’re calling a method with a return value

  • 0

Often we’re told things like,

If you’re calling a method with a return value that doesn’t change, take it out of the loop.

for example when writing code like:

for(int i=0; i < Instance.ExpensiveNonChangingMethod(); i++)
{
    // Stuff
}

I was wondering if you could some how tell the compiler that given the same inputs (and object instance) you would get the same outputs, so it would know it could move it out of the loop as part of the optimisation process.

Does anything like this exist? Perhaps something like code-contracts or spec#? Or can they already do this sort of thing?

Is it conceivable that the compiler could reason that a method is a pure function its-self?

Is there anything I can use in C# that will enable the compiler to perform more optimisation that it otherwise would? Yes i’m aware of premature optimisation. I’m asking mostly out of curiosity, but also if something like above did exist it would be ‘for free’ once the method was marked.

  • 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-27T16:01:02+00:00Added an answer on May 27, 2026 at 4:01 pm

    Some efficiency problems are detected by Microsoft FxCop, which is part of the Platform SDK.

    The list of 18 performance related issues it detects is here.

    It does not, however, detect the specific example you mentioned.

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

Sidebar

Related Questions

Often multiple applications share a large codebase of libraries that change often in development.
Often when learning about .NET I run into things that hail from the COM
Often times in unit tests I see people testing very simple things that realistically
Often my exe's have dll dependencies that I package with an installer like nsis
Often I add helper functions to my PHP that return complex HTML. For example,
Often, programmers write code that generates other code. (The technical term is metaprogramming ,
Often when I post a comment or answer on a site I like to
Often I see layouts on the iPhone like the one I attached. How is
Often I need to throw a custom(ized) error. Like when a resource cannot be
Often I want to check if a provided value matches one in a list

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.