private int numeroTelephone;
private string categorie;
public Contact(int numeroTelephone, string nom, string prenom, string categorie)
this.numeroTelephone = numeroTelephone;
this.categorie = categorie;
public int NumeroTelephone
get { return this.numeroTelephone; }
set { this.numeroTelephone = value; }
get { return this.prenom; }
set { this.nom = value; }
get { return this.categorie; }
set { this.categorie = value; }
return (this.numeroTelephone + "\t" + this.nom + "\t" + this.prenom + "\t" + this.categorie);
public static void TestLecture()
string nomFichier = "contacts.txt";
StreamReader fichierALire = new StreamReader(nomFichier);
while (fichierALire.Peek() > -1)
ligne = fichierALire.ReadLine();
Console.WriteLine(ligne);
public static Contact[] LectureFichier(string nomFich)
StreamReader fichierALire = new StreamReader(nomFich);
Contact[] contacts = new Contact[15];
char[] sep = new char[1] { ';' };
string[] datas = new string[4];
while ((fichierALire.Peek() > -1) && (i < 15))
ligne = fichierALire.ReadLine();
Console.WriteLine(ligne);
datas = ligne.Split(sep);
contacts[i] = new Contact(int.Parse(datas[0]), datas[1], datas[2], datas[3]);
static Contact RechercherNumeroTelephone(Contact[] contacts, int numeroTelephone)
for (int i = 0; i < contacts.Length; i++)
if (contacts[i].NumeroTelephone == numeroTelephone)
public static void Main(string[] args)
Contact[] contacts = null;
contacts = LectureFichier("contact.txt");
foreach(Contact contact in contacts)
Console.WriteLine(contact.Afficher());
Console.WriteLine("\n\n Recherches de contact");
Contact contact = RechercherNumeroTelephone(contacts,noTel);
Console.WriteLine(contact.Afficher());
Console.WriteLine("pas de contact");