static void Main(string[] args) { ExposesReadOnly exposesReadOnly = new ExposesReadOnly(); exposesReadOnly.AddSomeValue(); Console.WriteLine(exposesReadOnly.PublicList[1].Name); Console.ReadLine(); exposesReadOnly.PublicList[1].Name = "This is not possible!"; }
static void Main(string[] args) { //Here you create your dictionary and do some internal stuff (in this chase add some value from the inside) ExposesReadOnly dictionary = new ExposesReadOnly(); dictionary.AddSomeValue(); //You can read from the public list //This returns "SomeValue" Console.WriteLine(dictionary.PublicList[1].Name); Console.ReadLine(); //You cannot change the list from the outside dictionary.PublicList[1].Name = "This is not possible!"; }