Current location - Health Preservation Learning Network - Healthy weight loss - Structure is used in C#, and the definition of structure contains an array of another structure. How to define it?
Structure is used in C#, and the definition of structure contains an array of another structure. How to define it?
Structure b

{

int id

a[]suba;

};

When calling the program: babab.suba = newa [10]; The way.

However, this method is not recommended, and you can use classes instead of struct.

Note: It is best to add the public keyword to the variables in the structure.

Namely: struct b {public int id public a [] suba; }

Structure a

{

public int start

public int end

}

Structure b

{

Public int id

public a[]suba;

}

Static void Main(string[] args)

{

b newb

newb . id = 1;

newb . suba = new a[ 10];

newb.suba[0]。 start = 1;

newb.suba[0]。 end = 2;

newb.suba[ 1]。 start = 3;

newb.suba[ 1]。 end = 4;

Console. WriteLine("{0},{ 1},{2},{3} ",newb.suba[0]。 start,newb.suba[0]。 end,newb.suba[ 1]。 start,newb.suba[ 1]。 end);

Console. read();

}

Result output 1, 2, 3, 4