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

  • Home
  • SEARCH
  • 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 47299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:06:03+00:00 2026-05-10T16:06:03+00:00

What is the difference between const and readonly in C#? When would you use

  • 0

What is the difference between const and readonly in C#?

When would you use one over the other?

  • 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. 2026-05-10T16:06:04+00:00Added an answer on May 10, 2026 at 4:06 pm

    Apart from the apparent difference of

    • having to declare the value at the time of a definition for a const VS readonly values can be computed dynamically but need to be assigned before the constructor exits. After that it is frozen.
    • const‘s are implicitly static. You use a ClassName.ConstantName notation to access them.

    There is a subtle difference. Consider a class defined in AssemblyA.

    public class Const_V_Readonly {   public const int I_CONST_VALUE = 2;   public readonly int I_RO_VALUE;   public Const_V_Readonly()   {      I_RO_VALUE = 3;   } } 

    AssemblyB references AssemblyA and uses these values in code. When this is compiled:

    • in the case of the const value, it is like a find-replace. The value 2 is ‘baked into’ the AssemblyB‘s IL. This means that if tomorrow I update I_CONST_VALUE to 20, AssemblyB would still have 2 till I recompile it.
    • in the case of the readonly value, it is like a ref to a memory location. The value is not baked into AssemblyB‘s IL. This means that if the memory location is updated, AssemblyB gets the new value without recompilation. So if I_RO_VALUE is updated to 30, you only need to build AssemblyA and all clients do not need to be recompiled.

    So if you are confident that the value of the constant won’t change, use a const.

    public const int CM_IN_A_METER = 100; 

    But if you have a constant that may change (e.g. w.r.t. precision) or when in doubt, use a readonly.

    public readonly float PI = 3.14; 

    Update: Aku needs to get a mention because he pointed this out first. Also I need to plug where I learned this: Effective C# – Bill Wagner

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

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Simple: make all the DLLs in the process link to… May 11, 2026 at 11:47 am
  • added an answer The best approach to migrating to a usable design? CAREFULLY… May 11, 2026 at 11:47 am
  • added an answer I'd try something like this <link rel='stylesheet' href='/app_themes/blue/blue.css?v=<%=Global.VERSION_NUM%>'> Do that… May 11, 2026 at 11:47 am

Related Questions

What is the difference between const and readonly in C#? When would you use
What is the difference between a const_iterator and an iterator and where would you
What is the difference between early and late binding?
What is the difference between TrueType fonts and Type-1 fonts?
What is the difference between Build Solution and Batch Build in Visual Studio 2008?
What is the difference between a Group and a Match in .NET's RegEx?
What is the difference between publishing a website with visual studio and just copying
What is the difference between different optimization levels in GCC? Assuming I don't care
What is the difference between the AddRange and Concat functions on a generic List?
What is the difference between display:block and display:inline

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.