Uri class is very good example. in regards to collections i always expose IEnumerable and sometimes IReadOnlyList if index access is required. thanks for sharing.
I think collections is a bit of an adjacent topic, but yes, choosing the one that better fits the needs is important and quite often ignored (e.g. due to the ease of LINQ, many times people just use lists for everything when maybe a Dictionary or a Set would be better choices).
On that note, I usually try to avoid IEnumerable unless I specifically want something that might be lazy. In other occasions (e.g. a result from a repository or service call) I prefer using an IReadOnlyCollection which fits better with the already computed collection premise.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
hi João :)
Uri class is very good example. in regards to collections i always expose IEnumerable and sometimes IReadOnlyList if index access is required. thanks for sharing.
I think collections is a bit of an adjacent topic, but yes, choosing the one that better fits the needs is important and quite often ignored (e.g. due to the ease of LINQ, many times people just use lists for everything when maybe a
Dictionaryor aSetwould be better choices).On that note, I usually try to avoid
IEnumerableunless I specifically want something that might be lazy. In other occasions (e.g. a result from a repository or service call) I prefer using anIReadOnlyCollectionwhich fits better with the already computed collection premise.