-
I've always assumed that the compiler did the good ol' trick of reducing modulus (to an Benchmark:
Results:
There are times where const cannot be used and readonly is the only choice. I couldn't find an issue on this, so maybe I'm missing something obvious? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
readonly instance fields cannot be constant folded, you probably meant |
Beta Was this translation helpful? Give feedback.
No, it cannot, it may be changed with reflection and if you can't use const it is implied you have a more complex expression there. There is not much JIT can legally do in this case, only
static readonly
is allowed to be constant-folded.