This array is a stream of bytes. The problem with returning only the array is that it is not read-only, and therefore library clients can modify its contents.
There are so many different ways to wrap an array, I'm not sure what to choose:
IEnumerable, IList, List, ReadOnlyCollection, Collection, et cetera.
In addition, the return type may differ from the actual instance type.
My initial approach was to do something like this:
Data = new ReadOnlyCollection<byte>(data);
Where data is an array of bytes. The Data property will have some type of interface (IEnuerable, IList, etc.). However, I am not sure what to use. I see that many recommend IEnumerable, since it is pretty standard, but the order here matters, and the byte stream, in my opinion, should support syntactical similarities to an array. IEnumerable does not allow access to individual indicators, so this is clearly not an optimal choice.
IList is not readonly, so I suppose ICollection will be correct ..? Not sure. It seems that there are so many types of collections, and I'm a little confused about what to use.
source share