What is the benifit of a const funtion ?
On its own, not a lot - but when combined with the idea of a const
object or variable, it means you can have more safety. For instance,
suppose you maintain a byte array within a class, and you wish to make
that array available in a "read-only" kind of way - you could expose it
with a "const" property, which would mean that clients would have to
do:
const byte[] foo = myObject.MyProperty;
instead of
byte[] foo = myObject.MyProperty;
They then couldn't do
foo[0] = 5;
but they could do
byte x = foo[0];
It means you can basically return references to mutable objects, but
with the "const" modifier meaning that the client could only call
methods marked as "const" as well. (So for instance, in StringBuilder
ToString might be marked as "const", but Append wouldn't.)