Skip to main content
6 events
when toggle format what by license comment
Sep 30, 2012 at 12:25 comment added Kuba I have edited original post to add performance measurements and some conclusions.
Sep 30, 2012 at 11:35 comment added Peter Kiss Now i know that you are familiar with all these stuff i understand what you are like to tell us and the idea is not bad but i still think is unnecessary. With your solution the other side will enumerate on the collection through your collection and maybe not only once which will be slover then creating a brand new list (IEnumerable.ToList<T> is watching after ICollection implementation!).
Sep 30, 2012 at 10:51 comment added Kuba I was afraid that you would write that this is value type case :| That's not the case. If you would write: readOnlyCollection.ToList()[0] = new FooClass();then readOnlyCollection[0] still returns old reference. If collection is hosting reference types that support state change (through properties, methods, whatever), then they could be changed. But that's different context. You cannot blame ReadOnlyCollection for this. In this case it doesn't matter if objects are hosted in ReadOnlyCollection, List, Array or other IEnumerable implementation.
Sep 30, 2012 at 9:06 comment added Peter Kiss It will write out 0 but this is becouse integers are value types try this with a simple POCO class (one int type auto property).
Sep 30, 2012 at 8:28 comment added Kuba Am I ? You are expecting second WriteLine in following code to print '5' ? var collection = new ReadOnlyCollection<int>(new List<int>(new int[] { 0 })); Console.WriteLine(collection[0]); collection.ToList()[0] = 5; Console.WriteLine(collection[0]);
Sep 30, 2012 at 8:11 history answered Peter Kiss CC BY-SA 3.0