Timeline for Should I make a variable readonly when I modify it, but I don't actually set it outside of the constructor?
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 9, 2013 at 19:40 | vote | accept | It'sNotALie. | ||
Aug 9, 2013 at 19:04 | answer | added | Jesse C. Slicer | timeline score: 3 | |
Aug 9, 2013 at 18:55 | comment | added | Servy |
@SteveEvers The OP doesn't state that he isn't modifying the contents of the list after creation. There is only an indication that the reference to the list is not modified after creation. In fact, the OP state that the contents of the list are modified after creation ("I'm still modifying the list" ), so he's thinking that having readonly there would be confusing. Apparently it has confused you, so that would be a point in the "probably shouldn't add readonly" column.
|
|
Aug 9, 2013 at 18:53 | comment | added | It'sNotALie. | @SteveEvers How would it be? IEnumerable<T> has no insertion method. | |
Aug 9, 2013 at 18:51 | comment | added | Steven Evers | The functional difference between an IEnumerable<T> and List<T> is the ability to add and remove items (or, more specifically that IEnumerable<T> is immutable). Since the question indicates that the collection isn't modified after creation (only its contents) then IEnumerable<T> is a more fitting collection type. | |
Aug 9, 2013 at 18:50 | answer | added | Servy | timeline score: 4 | |
Aug 9, 2013 at 18:43 | comment | added | It'sNotALie. | @SteveEvers Why? What if I need to use it as a list? ;) | |
Aug 9, 2013 at 18:43 | comment | added | It'sNotALie. | @delnan I know the difference, it's just more of a style question. It's confusing to put it as readonly as although the reference is readonly, the value is not. | |
Aug 9, 2013 at 18:42 | comment | added | Steven Evers | Make it an IEnumerable<int> instead. | |
Aug 9, 2013 at 18:37 | comment | added | user7043 | It's only confusing if you the difference between references and objects isn't deeply ingrained in your brain. | |
Aug 9, 2013 at 18:22 | answer | added | Cameron | timeline score: 1 | |
Aug 9, 2013 at 18:12 | history | asked | It'sNotALie. | CC BY-SA 3.0 |