Make dictionary read only in C#

后端 未结 6 589
执笔经年
执笔经年 2020-12-18 20:24

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:26

    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.

提交回复
热议问题