1

The Dictionary<T, List<T>> is a private member and external methods should not modify its content. Therefore I want to create a public property making it readonly. But I don't know how to do it. It seems only possible when the value type of dictionary is not a mutable type.

AakashM
  • 62,551
  • 17
  • 151
  • 186
martinrhan
  • 362
  • 1
  • 18
  • Can you also please share some code where you've tried to accomplish your problem? Where is your problem when casting? – Chrᴉz remembers Monica Oct 01 '21 at 10:42
  • If you want to make sure that your original Dictionary is not modified, you usually either create a read-only copy on the fly when it is accessed, or you maintain a read-only copy and expose that. Otherwise, whoever accesses the reference can always cast it back to a mutable type. If you want your Dictionary to handle these operations itself, i'm afraid you have to code your own wrapper. – cboittin Oct 01 '21 at 14:05

0 Answers0