Did they ever explain why System.Array doesn't follow inheritance rules?



  • It's a Friday and I'm tired of casting obvious parameters because of this.

    System.Array inherits from System.Collections.ICollection.
    System.Collections.ICollection defines an int Count property.
    System.Array only has Length and not Count.

    Why?

    Is it like that funny business where I have to define but cover up GetEnumerator() to work right in some contexts (I forget why, this was years ago I read this)?

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
      foreach(mytype x in this.InternalList){yield return x;}
    }
    public System.Collections.Generic.IEnumerator<mytype> GetEnumerator()
    {
      foreach(mytype x in this.InternalList){yield return x;}
    }
    

  • 🚽 Regular

    @Zenith Why I don't quite understand is why explicit interface implementations become invisible without casting to the interface; which is what's happening here.

    258e5837-09af-4c6a-bda8-0a366623ec5c-image.png

    But perhaps the thing with the enumerators where the name and arguments are the same is a clue? I've got to leave so I can't think too much about this right now.


  • Considered Harmful

    Array is a framework construct propped up by a bunch of externs (native code) and as such is only larping as ICollection.


Log in to reply