Class Program
{
struct Student//define a student structure
{
public string name; Basic format
public int code;
public int age;
public int Fenshu;
}
static void Main (string[] args)
{
while (true)
{
ArrayList al = new ArrayList (); To define a new collection
Console.Write ("Please enter the number of people:");
int Renshu = Convert.ToInt32 (Console. ReadLine ());
for (int i = 0; i < Renshu; i++)
{
Student R = new Student (); Defines a variable of type R student, which can store numeric values
Console.Write ("Please enter student's name:");
R.name = Console.ReadLine ();
Console.Write ("Please enter student number:");
R.code = Convert.ToInt32 (Console.ReadLine ());
Console.Write ("Please enter Student Age:");
R.age = Convert.ToInt32 (Console.ReadLine ());
Console.Write ("Please enter student score:");
R.fenshu = Convert.ToInt32 (Console.ReadLine ());
Al. ADD (R); Put the value of R into the set of al.
}
for (int i = 0; i < Renshu; i++)//Sort by fractional bubble
{
for (int j = i; J < Renshu-1; J + +)
{
if (((student) al[i]) .fenshu< ((student) al[j+1]). Fenshu)//Take a good look at this code, not good understanding, student type in the value from AL
{
Student Zhong;
Zhong = (student) al[i];
Al[i] = al[j + 1];
Al[j + 1] = Zhong;
}
}
}
Console.WriteLine ("Post-row student order");
for (int i = 0; i < Renshu; i++)
{//Horizontal character output
Console.WriteLine ("Name" + ((student) al[i]). name+ "T-number" + ((student) al[i]). Code + "\ t fraction" + ((student) al[i]). Fenshu + "\ t age "+ ((student) al[i]). Age);
}
}
Console.ReadLine ();
Example: Enter the student's data, then reorder according to the student's score. Review the structure, collection, array, for loop, bubble sort, and the use of the horizontal character.