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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:31:36+00:00 2026-05-29T18:31:36+00:00

Will non-virtual properties to constant values be evaluated in compile time? (Like the constants

  • 0

Will non-virtual properties to constant values be evaluated in compile time? (Like the constants themselves)

Example:

class Clazz
{
    const int SPEED = 5;

    public int Speed 
    {
    get { return SPEED; }
    }
}

I know that any call to the constant SPEED will be evaluated once at compile time, but if I access the Clazz.Speed property from anywhere in my program, will that also be evaluated at compile time?

Edit: To evlove the question a little bit, will the next two examples be inlined by the Compiler (and not the JIT)? [ie. evaluated during compile time] :

// a static / non-static method that returns a constant value
(static) int GetConstant() { return 42; }

// a static / non-static property that returns a constant value
(static) int ConstProperty { get { return 42; } }
  • 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-29T18:31:39+00:00Added an answer on May 29, 2026 at 6:31 pm

    Running this through Linqpad produces the following IL for the getter:

    Clazz.get_Speed:
    IL_0000:  ldc.i4.5  //push integer value 5 on evaluation stack   
    IL_0001:  ret 
    

    This would mean that the getter is called at runtime (and not inlined) and returns a constant value.

    Hypothetically if the getter would be inlined in this case that would mean that the implementation of the property could not be changed without having to recompile any consuming assemblies – this would defeat using a property in the first place.

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

Sidebar

Related Questions

I'm trying to bind a function with a non-existent class. I will try to
If I do something like: Dog dog; //class with virtual methods Cat cat; //class
I'm looking to build a query that will use the non-clustered indexing plan on
I have a script which will be run interactively by non-technical users. The script
If I define a non-member function in a header, will it always be inlined
TL;DR: Adding any non-built-in functions to Array.prototype AND Function.prototype will cause the IE8 native
Possible Duplicate: Why C# implements methods as non-virtual by default? It would be much
Consider the following class hierarchy: base class Object with a virtual method foo() an
I have a class template where some methods are defined as virtual to give
Let's say we have a class that looks like this: class A { public:

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.