|
|
|
|
|
by kroltan
1492 days ago
|
|
C# does not (as far as I know) have readonly or const for local variables, only to fields. You can even have consts inside method bodies, but they are only actual compile-time constants. codeflo means to declare a local variable that cannot be reassigned later. void Foo() {
// this is possible in C# today, but only for compile-time constants
const int Bar = 42;
// this is what codeflo wants: variables that cannot be changed after declaration, but can hold runtime values
readonly string text = $"Blah: {Bar + System.Environment.ProcessorCount}";
// with such a variable, you wouldn't be able to reassign it later:
text = "Some other text";
// the line above would be a compile-time error, just like trying to reassign to a readonly field.
}
|
|