Make dictionary read only in C#

后端 未结 6 830
一向
一向 2020-12-18 20:37

I have a Dictionary> and would like to expose the member as read only. I see that I can return it as a IReadOnlyDictionar

6条回答
  •  庸人自扰
    2020-12-18 21:22

    https://msdn.microsoft.com/en-us/library/acdd6hb7.aspx

    You can use this to expose the object as readonly.

    You could also use properties get; set; and only allow the get to be public.

    But Matias answer seems to be more fitting.

提交回复
热议问题