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

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

    There is a gotcha with consts! If you reference a constant from another assembly, its value will be compiled right into the calling assembly. That way when you update the constant in the referenced assembly it won't change in the calling assembly!

提交回复
热议问题