static List <Telephone> CreateList(string path) { List <Telephone> tels = new List <Telephone>(); StreamReader monStreamReader = new StreamReader(path); string ligne = monStreamReader.ReadLine(); int lineCounter = 1; while (ligne != null) { string[] temp = ligne.Split(','); try { if (temp[0] == "Fixe") { TelephoneFixe fixe = new TelephoneFixe(temp[1], temp[2], temp[3]); tels.Add(fixe); } else { TelephonePortable portable = new TelephonePortable(temp[1], temp[2], temp[3]); tels.Add(portable); } ligne = monStreamReader.ReadLine(); lineCounter++; } catch (IndexOutOfRangeException e) { Console.WriteLine("Une erreur est survenue. Merci de vérifier que le fichier est bien formaté à la ligne " + lineCounter); ligne = monStreamReader.ReadLine(); } } monStreamReader.Close(); return(tels); }
public int comparerAutre(object tel) { if (tel == null) { return(1); } TelephoneFixe otherTel = tel as TelephoneFixe; if (otherTel != null) { return(this.bureau.CompareTo(otherTel.bureau)); } else { throw new ArgumentException("Object is not a Temperature"); } }