Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>in c# we having const or readonly keyword to declare a constant.</p> <p><strong>const</strong></p> <p>A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the const keyword and must be initialized as they are declared. For example;</p> <pre><code>public class MyClass { public const double PI = 3.14159; } </code></pre> <p>PI cannot be changed in the application anywhere else in the code as this will cause a compiler error.</p> <p><strong>readonly</strong></p> <p>A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:</p> <pre><code>public class MyClass { public readonly double PI = 3.14159; } </code></pre> <p>or</p> <pre><code>public class MyClass { public readonly double PI; public MyClass() { PI = 3.14159; } } </code></pre> <p>Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example:</p> <pre><code>public static readonly uint l1 = (uint)DateTime.Now.Ticks; </code></pre> <p><strong>Notes</strong></p> <p>readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.</p> <p>A readonly member can hold a complex object by using the new keyword at initialization. readonly members cannot hold enumerations.</p> <p>credit goes here: <a href="http://www.dotnetspider.com/forum/69474-what-final-c-i-need-detailed-nfo.aspx" rel="nofollow">http://www.dotnetspider.com/forum/69474-what-final-c-i-need-detailed-nfo.aspx</a></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.
    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