Is there a difference between private const and private readonly variables in C#?

后端 未结 9 1059
鱼传尺愫
鱼传尺愫 2020-12-29 03:04

Is there a difference between having a private const variable or a private static readonly variable in C# (other than having to assign the co

9条回答
  •  长发绾君心
    2020-12-29 03:27

    In use? Not really. Consts are evaluated at compile time, whereas readonly are evaluated at runtime. You can also assign a readonly variable a value in the constructor.

提交回复
热议问题