Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. CO"If the collection should not be changed by the outside world use IEnumerable<T>" - I disagree with this characterisation. Returning IEnumerable<T> won't help if the object referenced by the return value is a mutable list - the caller can always cast. You should return IEnumerable<T> if the caller should only be able to enumerate, ICollection<T> if he also needs a Count, and IList<T> if he will need indexed access. In **all** of the above cases, if the collection should not be changed by the outside world, wrap it in a readonly collection (e.g. using List<T>.AsReadOnly).
      singulars
    2. CO@Joe: I'm not a fan of that argument. The caller can always try to cast **anything** you give it to *anything* else - it's simply poor design to do so. You can wrap all results in a `ReadOnlyCollection<T>` if you want, but that won't protect you against *hostile* callers; they can just use Reflection to get at the internal mutable list. If this is ultra-secure code then the only way to guarantee this particular invariant is return a *new*, generated `IEnumerable<T>` instance, i.e. by returning `originalEnumerable.Select(x => x).ToArray()`.
      singulars
    3. COBut in any event, the recommendations are from a discoverability and code-maintenance perspective (writing self-documenting code), not a security perspective; if you're in the latter camp then you have *many* other things to worry about. It's also the reason why I used the phrase "should not" as opposed to "must not" - it's not a guarantee, just a very strong hint. `ReadOnlyCollection<T>` will give a *runtime* error if a modification is attempted; you want to catch such errors at *compile-time* whenever possible.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload