Thread: question about arrays' generic interface implementation/inheritance

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    71

    question about arrays' generic interface implementation/inheritance

    For a change, I'll talk about programming...

    In .net 3.5, all arrays derive from the System.Array class.

    Code:
    (this piece of code proves it:
    Console.WriteLine(new int[] { 1, 2, 3 }.GetType().BaseType);)
    //System.Array
    System.Array derives from System.Object.

    System.Array implements the following interfaces:

    System.ICloneable
    System.Collections.ICollection
    System.Collections.IEnumerable
    System.Collections.IList

    but after running this code

    Code:
              Type t = new int[0].GetType();
                  Type[] tt  = t.GetInterfaces();
                foreach (Type u in tt)
                Console.WriteLine(u);
    I discovered that arrays not only inherit the implementation of the above interfaces but also (if I'm reading this properly) implement IList<T>, ICollection<T>, IEnumerable<T>.

    can someone explain the reasoning behind arrays' implementing those 3 generic interfaces rather than having System.Array implement them and then letting the arrays inherit those implementations?
    Last edited by y99q; 11-21-2011 at 02:39 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    System.Array isn't generic so it can't implement those generic interfaces.
    As for why it isn't generic is probably a relic due to backwards compatibility.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 07-01-2011, 11:35 AM
  2. Seperating interface and implementation
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2010, 08:59 PM
  3. interface implementation
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 05-04-2008, 12:46 AM
  4. Replies: 5
    Last Post: 06-19-2006, 03:43 PM
  5. interface, implementation, & application files
    By trongsi in forum C++ Programming
    Replies: 4
    Last Post: 04-08-2006, 02:11 PM