Mike
Mike

Reputation: 257

How to write the class so a several lists will be nested inside it?

I want to have a class of 12 months that every month include 6 parts.every parts is a list of float numbers.

I used these classs, but I can't access to list of float numbers:

    class months
    {
        parts m1 = new parts();
        parts m2 = new parts();
        parts m3 = new parts();
        parts m4 = new parts();
        parts m5 = new parts();
        parts m6 = new parts();
        parts m7 = new parts();
        parts m8 = new parts();
        parts m9 = new parts();
        parts m10 = new parts();
        parts m11 = new parts();
        parts m12 = new parts();

    }

    class parts
    {
        List<float> p1;
        List<float> p2;
        List<float> p3;
        List<float> p4;
        List<float> p5;
        List<float> p6;
    }

 months aa = new months();

I want to add number to float list like this:

months aa = new months();

aa.m1.p1.add(11.5);

which is better in this case ,struct or class?

Upvotes: 0

Views: 28

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101681

Your fields are private. You need to make them public:

class months
{
    public parts m1 = new parts();
    public parts m2 = new parts();
    ...
}

class parts
{
    public List<float> p1;
    public List<float> p2;
    ...
}

Also you need to initialize fields of parts class.

Upvotes: 1

Related Questions