variable that can't be modified

后端 未结 9 1821
我寻月下人不归
我寻月下人不归 2021-01-04 02:14

Does C# allow a variable that can\'t be modified? It\'s like a const, but instead of having to assign it a value at declaration, the variable does not have any

9条回答
  •  心在旅途
    2021-01-04 03:12

    You can define a readonly variable that can only have it's value set in the objects constructor.

    Read about it here: http://msdn.microsoft.com/en-us/library/acdd6hb7%28v=VS.100%29.aspx

提交回复
热议问题