Structural body
The format of the struct:
Struct variable name
{
Public type variable name ;
}
If the struct is defined in the main function, it can only be used in the main function, the general structure is defined before the main function, all the places inside the main function can be used, and the parameters are preceded by public to represent the common variables
Usage:
Used in the main function: X1 i= new X1 (); Defines a struct of type x1 named I
Assignment: struct name + dot + struct body inside variable name = value;
i.a=12;
structure body Structure body:
Struct x1
{
public int A;
Public X2 Z; The declaration of a X2 type of z,x2 is another type of struct we define.
}
struct X2//This is the definition of a struct named X2
{
public string S;
}
How to use Structure body assignment: x1 i = new X1 ();
I. Z. s = "Hello!" ";
Structural bodies in C #