What is the difference between const and readonly in C#?

前端 未结 30 2816
挽巷
挽巷 2020-11-22 05:05

What is the difference between const and readonly in C#?

When would you use one over the other?

30条回答
  •  情深已故
    2020-11-22 05:30

    Principally; you can assign a value to a static readonly field to a non-constant value at runtime, whereas a const has to be assigned a constant value.

提交回复
热议问题