Const VS ReadOnly
Here I explain in detail the differences between Const and ReadOnly.
For ref:
https://www.youtube.com/watch?v=Aj26MiCUeYA
Fundamental behavior to both is the same! Once a value has been assigned it can NOT be changed at run time
Constant values must have a primitive type for the value type (int, string, - when you assign a value to a const this value MUST be known at compile time!
Const variables are static by default.
Marking a variable as static means it would be part of the type state as opposed to being part of an object state.
Read only can be static , it's a choice, and we can evaluate it's value at run time.
Therefore you can NOT have something like:
private const int myAge; -> You must set the value when you declare
But, for a readonly field we can and later in the ctor of the class give the value:
private readonly int herAge;
When you defined a field as readonly it's the REFERANCE that becomes immutable NOT the object
private static readonly int[] numbers = new[] { 10, 20, 30 };
you can NOT change numbers like that: numbers = new[] {30,40,50 };
But YOU CAN change the object that it points to. Like, number[1] = 55;