Answer the question
In order to leave comments, you need to log in
C# - single read/write variable in syntax?
Hello.
How to set a one-time entry variable in syntax?
That is, after writing (not in the constructor, at any time), it becomes readonly.
It is not a question to make a property, I want a short one-line version when declaring.
Is there such a possibility? (before C# 7.3).
Is there an option for reading (after the first reading, other results are 0/null/false )
There was a desire to know how to implement similar behavior for the field.
Answer the question
In order to leave comments, you need to log in
Write your generic class, with your one-time logic.
You can take it as a basis https://github.com/microsoft/referencesource/blob/...
A write-once variable can be declared with const
(
public , private const /*тип данных*/ /*имя переменной*/ = /* значение*/ ;
void main(string []arg){
const /*тип данных*/ /*имя переменной*/ = /* значение*/ ;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question