Readonly field that could be assigned a value outside constructor

后端 未结 7 1895
清酒与你
清酒与你 2021-01-22 16:19

Is there a way to have a private readonly field in a class that could be assigned a value anywhere in the class, but only once??

That is, I am looking for a private read

7条回答
  •  不思量自难忘°
    2021-01-22 16:57

    There's no language support for that, but you could make a setter, which implemented the desired behavior. Obviously that would not give you compile time errors, but without the language support that is probably the best you can do.

提交回复
热议问题