What does immutable and readonly mean in C#?

前端 未结 8 977
我寻月下人不归
我寻月下人不归 2021-02-13 09:44

Is it correct that it is not possible to change the value of an immutable object?

I have two scenarios regarding readonly that I want to understand:

8条回答
  •  逝去的感伤
    2021-02-13 10:15

    private readonly ICollection _items;

    Does not prevent items from being added. This simply prevents _items from being re-assigned. The same is true for _metadata. Accessible members of _metadata can be changed - _metadata cannot be re-assigned.

提交回复
热议问题