...

/

Should a Parameter be const or immutable?

Should a Parameter be const or immutable?

This lesson explains when a parameter should be const and when it should be immutable.

We'll cover the following...

Our discussion so far shows that because they are more flexible, const parameters should be preferred over immutable parameters. This is not always true.
const erases the information about whether the original variable was mutable or immutable. This information is hidden even from the compiler.

A consequence of this fact is that const parameters cannot be passed as arguments to functions that take immutable ...

Access this course and 1400+ top-rated courses and projects.