0

I was looking at the Class definition of System.Array class which implements following interfaces ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable. I realized that this class doesn't implements all properties/methods define the interfaces, which it is implementing. Eg. IList interface has following declaration:

public interface IList : ICollection, IEnumerable
{
    object this[int index] { get; set; }
    bool IsFixedSize { get; }
    bool IsReadOnly { get; }
    int Add(object value);
    void Clear();
    bool Contains(object value);
    int IndexOf(object value);
    void Insert(int index, object value);
    void Remove(object value);
    void RemoveAt(int index);
}

However System.Array class implements only following properties from IList interface:

public bool IsFixedSize { get; }
public bool IsReadOnly { get; }

Please help me out here.

Saurabh Saxena
  • 117
  • 1
  • 11
  • 1
    Did you read [the documentation for `System.Array`](https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx)? [All `IList` members are (explicitely) implemented](https://msdn.microsoft.com/en-us/library/system.array(v=vs.110).aspx#Explicit%20Interface%20Implementations). – Uwe Keim Apr 16 '18 at 06:31
  • You need to read about [explicit interface implementation](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation). – InBetween Apr 16 '18 at 06:58
  • Possible duplicate of [C# Interfaces. Implicit implementation versus Explicit implementation](https://stackoverflow.com/questions/143405/c-sharp-interfaces-implicit-implementation-versus-explicit-implementation) – ASh Apr 16 '18 at 07:26
  • Well, the [`Array.Add()` method](https://msdn.microsoft.com/en-us/library/bb342410(v=vs.110).aspx) is "implemented" to throw an exception. I actually think that the design of this is bad, because `Array` violates the [Liskov Substitution Principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle) because of it. – Matthew Watson Apr 16 '18 at 07:51

0 Answers0