Does a struct with an array filed make sense?

Viewed 117

I've the following struct with an array as second field:

public struct UncNumber
{
    private double _value;
    private DependsOn[] _dependencies;

    public double Value { get { return _value; } }
    public DependsOn[] Dependencies { get { return _dependencies; } }

    public UncNumber(double value, DependsOn[] dependencies)
    {
        _value = value;
        _dependencies = dependencies;
    }
}

By the way the DependsOn struct looks like that:

public struct DependsOn
{
    private int _input;
    private double _jacobi;

    public int Input { get { return _input; } }
    public double Jacobi { get { return _jacobi; } }

    public DependsOn(int input, double jacobi)
    {
        _input = input;
        _jacobi = jacobi;
    }
}

I looked at the following resources:

But I didn't came to a conclusion yet if I should use a struct or a class for UncNumber. I've the following additional comments why I think a struct is the better choice in this case:

  • I'm using the above UncNumber structure for mathematical computation, similiar like I could use the Complex Structure.
  • I'm having a lot of methods which use arrays of the UncNumber struct. E.g.: matrix multiplication UncNumber[,] Dot(UncNumber[,] a, UncNumber[,] b).
  • A lot of the instances of the UncNumber struct will be very short-lived and immutable.
  • The instance size of the UncNumber struct is 16 bytes (8 bytes for the double Value and 8 bytes for the reference type / array Dependencies).

Or does a struct with an array field not make sense at all?

0 Answers
Related