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

前端 未结 30 2840
挽巷
挽巷 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:45

    I believe a const value is the same for all objects (and must be initialized with a literal expression), whereas readonly can be different for each instantiation...

提交回复
热议问题