views:

17

answers:

1

Hi, I'm puzzled about arrays in C#.

I can't find any documentation on MSDN about for example the object double[]. I do find documentation about int, array, collections, ... but can't find out of what type double[] is. If I do double[] a = new double[10]; a.GetType(), I find that the type of a is System.Double[]

I believe that the type is not System.Double[], but must be some descendent of an object or interface in the System.Collections namespace or the System.Collections.Generic namespace. My best guess is that a double[] is a type that implements the interface System.Collections.IList, but I'm not sure at all.

So, could anyone explain me what kind of object an array of doubles (so an object double[]) really is? What are it's base classes, which interfaces does it implement, ... Where could I find documentation on arrays of objects defined as int[], ..., object[] ?

Thanks!

A: 

Hi The System.Array is a base class for all types of arrays int, double, string whatever, the base class for System.Array is System.Object. so the correct type is System.Double[]. It implements the ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable interfaces as stated on msdn. The main difference between arrays and collection is that arrays cannot be changed in size at runtime and arrays have to contain objects of same type as opposed to collections.

MadalinaA
Thanks a lot! Why can't I implement System.Array in a custom class? Or better, why don't they allow me to do this?
Wice
Not sure what do you mean by implementing System. Array in a custom class. I presume you would want to use it as a base class and derive from it. That is not possible, because in the framework there are some classes which were intended to never get instantiated and therefore are marked as static. Among those classes are Math, ThreadPool and Array.If you want to add additional functionality to the Array class try using extension methods.
MadalinaA