C# equivalent of a const pointer/pointer to const in C++
c#, c++, clr, constants
Solution
There is no direct equivalent to passing references as 'const' in C#, but there are alternative ways to accomplish its purpose. The most common way to do this is to make your reference class either completely immutable (once constructed, its state should never change) or pass it as an immutable public interface. The latter is the closest to the intention of the 'const' parameter contract (I'm giving you a reference to something so you can use it, but I'm asking you not to change it.) A poorly-behaved client could 'cast away' the public interface to a mutable form, of course, but it still makes the intention clear. You could 'cast away' const in C++, as well, thought this was rarely a good idea.
One other thing in C++ is that you would often prefer to pass as const when you knew that the lifetime of the reference you were passing was limited in scope. C++ often follows the pattern where objects are created and destroyed on the stack within method scope, so any references to those objects should not be persisted outside that scope (since using them after they fall out of scope could cause really nasty stack corruption crashes.) A const reference should not be mutated, so it's a strong hint that storing it somewhere to reference later would be a bad idea. A method with const parameters is promising that it's safe to pass these scoped references. Since C# never allows storing references to objects on the stack (outside of parameters), this is less of a concern.
Problem
I am learning the basics of C++, coming from the .NET world (C#). One topic i found interesting was the const keyword and its usage with pointers (const pointer/pointer to const). I'd like to know if there's any C# language equivalent of the const pointer/pointer to const that C++ has? (I know C# doesn't have pointers, i am considering references to be the pointer-like types in C#). Also, out of interest, if there's no such equivalent, what were the decisions behind not including such a feature?