Is there a way to tell the compiler that the result of an expression shall be considered immutable from this place onward?
...
"const" MyClass str = b[0].x+b[1].x;
... // from here on str is an immutable object
And have const or readonly variable a performance benefit?
Added: @Onur: (a) the assignment of a new value shall be allowed; (b) the current value of str shall not be allowed, that includes everything that can be accessed via str, eg any field of str as well as everything that is reference in any way by str; (c) Example might be difficult. But I try to rephrase it. str shall be any kind of datastructure (object, collection and any mixture of that). The object that will be assigned to str is mutable and can be modified by another reference. But when assigned to str, I want to make sure that via str no modification of the object is possible. The idea behind that is, that the object, once created, will be passed to differenct threads to work with the data of the object and I want to make sure that I do not accidently modify the object that is passed to the different threads by reference. So I want some kind of reference that prevents my from modifying any data. Let's say I want some kind of reference that makes the complete object readonly.