Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Static readonly can be assigned at constroctor whereas the const cannot. Also, the getter does not have to return a constant value, the value van be a private member, which can be changed in another part of the class, or be a calculated value.</p> <p>From <a href="http://msdn.microsoft.com/en-us/library/acdd6hb7.aspx" rel="nofollow">readonly (C# Reference)</a></p> <blockquote> <p>The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants as in the following example:</p> </blockquote> <pre><code>public static readonly uint timeStamp = (uint)DateTime.Now.Ticks; </code></pre> <blockquote> <p>The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.</p> </blockquote> <p>From <a href="http://msdn.microsoft.com/en-us/library/e6w8fe1b%28v=vs.90%29.aspx" rel="nofollow">const (C# Reference)</a></p> <blockquote> <p>The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable is constant, which means it cannot be modified.</p> </blockquote> <p>Also, the are different in the intellisense as they are different compile time objects</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload