public void NhapTuFile() { string path = "E:\\data1.txt"; StreamReader sr = new StreamReader(path); HinhHoc hh = null; string str = " ", kieuHinh; while ((str = sr.ReadLine()) != null) { string[] line = str.Split(' '); kieuHinh = line[0]; switch (kieuHinh) { case "HV": hh = new HinhVuong(float.Parse(line[1])); break; case "HT": hh = new HinhTron(float.Parse(line[1])); break; case "HCN": hh = new HinhChuNhat(float.Parse(line[1]), float.Parse(line[2])); break; } Them(hh); } }
public void Them(HinhHoc hh) { collection.Add(hh); }