Content deleted Content added
Line 193:
Further, because C and C++ expose pointers and references directly, there is a distinction between whether the pointer itself is constant, and whether the data pointed to by the pointer is constant. Applying <code>const</code> to a pointer itself, as in <code>SomeClass * const ptr</code>, means that the contents being referenced can be modified, but the reference itself cannot (without casting). This usage results in behaviour which mimics the behaviour of a <code>final</code> variable reference in Java. By contrast, when applying const to the referenced data only, as in <code>const SomeClass * ptr</code>, the contents cannot be modified (without casting), but the reference itself can. Both the reference and the contents being referenced can be declared as <code>const</code>.
==C#
C#
Regarding the final keyword, C# has two related keywords:
For methods and classes use <code>sealed</code>, however for the variables use <code>readonly</code> <ref>[https://stackoverflow.com/questions/1327544/what-is-the-equivalent-of-javas-final-in-c What is the equivalent of Java's final in C#?]</ref>▼
# The equivalent keyword for methods and classes is <code>sealed</code>
▲
Note that the difference between <code>const</code> and <code>readonly</code> is that const is evaluated at compile time, however, readonly is evaluated at runtime, thus can has a runtime expression to be calculated and fixed at runtime.▼
▲Note that
==References==
|