public void Them(MayTinh mt) => listMayTinh.Add(mt);
public void ImportFromFile() { //string path = "E:\\data.txt"; string path = @"maytinh.txt"; Write("Nhap ten tap tin de mo >> "); string keyOpen = ReadLine().ToLower(); string keyWord = ".txt"; string a; if (keyOpen.Contains('.')) { a = $@"{keyOpen}"; } else { a = $@"{keyOpen + keyWord}"; } if (a != path) { Write("\nFail! Please try..."); Read(); return; } else { Write("\nAccess..."); } StreamReader file = new StreamReader(a); string str = ""; while ((str = file.ReadLine()) != null) { MayTinh mayTinh = new MayTinh(); string[] s = str.Split('*'); mayTinh.TenMayTinh = s[0]; foreach (string item in s) { if (item.IndexOf("CPU") == 0) { mayTinh.Them(new CPU(item)); } if (item.IndexOf("RAM") == 0) { mayTinh.Them(new RAM(item)); } if (item.IndexOf("HDD") == 0) { mayTinh.Them(new HDD(item)); } if (item.IndexOf("Mainboard") == 0) { mayTinh.Them(new Mainboard(item)); } if (item.IndexOf("Power") == 0) { mayTinh.Them(new Power(item)); } } Them(mayTinh); } }