public static void SapXep(List <Hang> list) { for (int i = 0; i < list.Count - 1; i++) { for (int j = i + 1; j < list.Count; j++) { if (list[i].ThanhTien() > list[j].ThanhTien()) { Hang temp = new Hang(); temp = list[i]; list[i] = list[j]; list[j] = temp; } } } }
static void Main(string[] args) { List <Hang> list = new List <Hang>(); int n; Console.Write("Nhap so luong mat hang: "); n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { Hang temp = new Hang(); temp.Nhap(); list.Add(temp); } Hang.SapXep(list); foreach (Hang temp in list) { temp.Xuat(); } Console.ReadKey(); }