Skip to content

Why can object initializes assign 'init' but not 'readonly' #8409

Answered by huoyaoyuan
zms9110750 asked this question in General
Discussion options

You must be logged in to vote

Isn't init used as a substitute for readonly on property?

No. Getter-only auto properties corresponds to readonly fields. They can be assigned in constructor.

Why does he have an additional permission?

readonly means it can only be set by the object itself, in constructor. init allows initialization from the caller that uses the object.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jnm2
Comment options

Answer selected by zms9110750
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants