First of all, I would recommend using
System.Collection.Generic.List
with proper type argument instead of
ArrayList
which became obsolete with introduction of
generics; this type force you into doing type cases, which is inherently error-prone.
Instead of the type double[2] you use (as I understand, one element is Mass, another is Intensity), you need to use explicit structure with explicit names:
use List = System.Collection.Generic.List<Element>;
struct Element {
internal Element(double mass, double intensity) { Mass = mass; Intensity = intensity; }
internal double Mass;
internal double Intensity;
}
List masslistArray = new List();
masslistArray[0] = new Element(6, 55);
Create another array in the same way of the same type or of the similar type but with the element type different similar structure. Then you can access elements of index (within available
Length
(this is the instance property of
List
)) or adding elements via
Add
method. Using indexed access you can assign elements element-to-element.
If you want to have different element types for different array, but there is a semantic way to convert it component-by-component, you can create an implicit convertions operator, for example:
struct Point {
}
struct Element {
public static implicit operator Point(Element value) {
return new Point(value.Mass, 0, );
}
}
Without the operator you would have to assign between different types one per component basis (each double member separately, for example), the operator will allow to assign array elements directly.
For arrays of the same type you can also use
Array.Copy
to make slices and copy part of one array onto another one.
—SA