c# - Why array implements IList? -


see definition of system.array class

public abstract class array : ilist, ... 

theoretically, should able write bit , happy

int[] list = new int[] {}; ilist ilist = (ilist)list; 

i should able call method ilist

 ilist.add(1); //exception here 

my question not why exception, rather why array implements ilist?

because array allows fast access index, , ilist/ilist<t> collection interfaces support this. perhaps real question "why there no interface constant collections indexers?" , have no answer.

there no readonly interfaces collections either. , i'm missing more constant sized indexers interface.

imo there should several more (generic) collection interfaces depending on features of collection. , names should have been different too, list indexer stupid imo.

  • just enumeration ienumerable<t>
  • readonly no indexer (.count, .contains,...)
  • resizable no indexer, i.e. set (add, remove,...) current icollection<t>
  • readonly indexer (indexer, indexof,...)
  • constant size indexer (indexer setter)
  • variable size indexer (insert,...) current ilist<t>

i think current collection interfaces bad design. since have properties telling methods valid(and part of contract of these methods) doesn't break substitution principle.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -