struct: is a custom collection that can put all kinds of elements in the same way as a collection.
Example of a definition:
struct student
{
public int nianling;
public int Fenshu;
public string name;
public string sex;
public int sum;
}
The above statement defines a struct, named student, that contains the age, fraction, sum, and string type name, and gender of type int.
Second, usage:
A struct called student is defined outside main main function for use in the main function.
Student st = new Student ();//The phrase is defined in the main function as a struct of type student named St.
The following begins to assign values to each element inside: (struct name + dot + variable name = value inside struct)
Under Main function
{
st.nianling=22;
st.fenshu=80;
St.name= "Xiao Li";
}
The assigned value can be printed after the assignment is complete.
Third, the structure type contains the structure of the body type:
You can define a struct in the previous student structure
Public Shuxing sx;//represents a shuxing struct variable group
}
public struct shuxing
{
public double Tizhong;
public double Shengao;
public int nianling;
public string Hunfou;
}
This will save you the ability to initialize the structure again when you use it.
struct Jiegouti
//{
public string name;
public string Kecheng;
Public Fen Fenshu;
//}
struct Fen
//{
public double Yufen;
public double Shufen;
public double Yingfen;
//}
The equals sign, meaning in the enumeration type
Point to an index number
Enum Meiju:int
{
One=1,
Two=0,
Three,
If it is equal to a constant that appears before, the constant will be taken directly.
Four
}
struct student//Create a student's structure
{
public int code;//Number
public string name;//Name
public double score;//Fraction
}
static void Main (string[] args)
{
ArrayList al = new ArrayList ();//Initialize Collection
Console.Write ("Please enter class Number:");
int n = Int. Parse (Console.ReadLine ());
for (int i = 0; i < n; i++)
{
Student st = new Student ();//Initialize struct
Console.Write ("Please enter the student number of {0}:", i+1);
St.code = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter his/her name:");
St.name = Console.ReadLine ();
Console.Write ("Please enter his/her score:");
St.score = Double. Parse (Console.ReadLine ());
Al. Add (ST);//Adds St This struct object into the Al collection
}
Console.WriteLine ("All personnel information entered! Please press ENTER to view! ");
Console.ReadLine ();
Console.WriteLine (Al[0]);
for (int i = 0; i < n; i++)
{
Student st = (student) al[i];
Console.WriteLine ("{0}" Student's study number is {1}, the name is {2}, the result is {3} ", I + 1, st.code, St.name, St.score);
}
Console.ReadLine ();
Console.WriteLine ((int) meiju.one);
Console.WriteLine ((int) meiju.two);
Console.WriteLine ((int) meiju.three);
Console.WriteLine ((int) meiju.four);
Console.ReadLine ();
struct initialization
Jiegouti JGT = new Jiegouti ();
Jgt.name = "Zhang San";
Jgt.kecheng = "Language";
Jgt.fenshu = 99;
jgt.fenshu.yufen=55;
Jgt.fenshu.shufen = 88;
Jgt.fenshu.yingfen = 99;
Jiegouti JGT2 = new Jiegouti ();
C # Infrastructure Body enumeration types