G
G
GFX Data2020-07-02 13:29:26
C++ / C#
GFX Data, 2020-07-02 13:29:26

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

2 answer(s)
F
freeexec, 2020-07-02
@ShockWave2048

Write your generic class, with your one-time logic.
You can take it as a basis https://github.com/microsoft/referencesource/blob/...

D
Dmitry Pavlov, 2020-07-02
@Stalker31

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 question

Ask a Question

731 491 924 answers to any question