1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace 冒泡排序
7 {
8
9 在其他类中定义一组变量
10 class Student
11 {
12 public string Code;
13 public string Name;
14 public decimal Score;
15 }
16 }
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6
7 namespace 冒泡排序
8 {
9 class Program
10 {
11
12 static void Main(string[] args)
13 {
14 ArrayList arr = new ArrayList();
15
16 Student s = new Student(); //实例化
17
18 s.Code = "101";
19
20 Student s1 = new Student();
21 s1.Code = "102";
22
23
24 arr.Add(5);
25 arr.Add(6);
26 arr.Add(8);
27 arr.Add(1);
28 arr.Add(3);
29
30 foreach (object o in arr)
31 {
32 Console.WriteLine(o);
33 }
34
35 Console.WriteLine("---------------------------------");
36
37 for (int i = 0; i < arr.Count; i++)
38 {
39 for (int j = i + 1; j < arr.Count; j++)
40 {
41 if (Convert.ToInt32(arr[i]) < Convert.ToInt32(arr[j]))
42 {
43 int zhong = 0;
44
45 zhong = Convert.ToInt32(arr[i]);
46 arr[i] = arr[j];
47 arr[j] = zhong;
48 }
49 }
50 }
51
52 foreach (object o in arr)
53 {
54 Console.WriteLine(o);
55 }
56
57
58 Console.ReadLine();
59 }
60 }
61 }
![]()