C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
what's wrong with my code? Posted by chickenpoo on 9 Mar 2012 at 9:46 AM
class Personne
{
private char sexe;
private string nomPre, taille, poids;
private int numero;

public Personne(string nomPre, char sexe, string taille, string poids, int numero)
{
this.nomPre = nomPre;
this.sexe = sexe;
this.taille = taille;
this.poids = poids;
this.numero = numero;
}

public Personne(string ligneLue)
{
string nomPre = ligneLue.Substring(0,30).Trim();
char sexe = char.Parse(ligneLue.Substring(31,7).Trim());
string taille = ligneLue.Substring(38,14).Trim();
string poids = ligneLue.Substring(53,12).Trim();
int numero = int.Parse(ligneLue.Substring(66).Trim());
}

public string GetNomPre()
{
return nomPre;
}

public char GetSexe()
{
return sexe;
}

public string GetTaille()
{
return taille;
}

public string GetPoids()
{
return poids;
}

public int GetNumero()
{
return numero;
}

//accesseurs

public void SetNomPre(string nomPre)
{
this.nomPre = nomPre;
}

public void SetSexe(char sexe)
{
this.sexe = sexe;
}

public void SetTaille(string taille)
{
this.taille = taille;
}

public void SetPoids(string poids)
{
this.poids = poids;
}

public void SetNumero(int numero)
{
this.numero = numero;
}

//modificateurs

public void Afficher()
{
Console.WriteLine("{0} {1} {2} {3} {4}", nomPre, sexe, taille, poids, numero);
}
}

class Texte
{
static void LireFichier(string nomFichier, Personne[] pers)
{
int n = 0;
Console.WriteLine("\nOn lit le fichier texte " + nomFichier);

StreamReader aLire = File.OpenText(nomFichier);
string ligneLue = null;

while ((ligneLue = aLire.ReadLine()) != null)
{
for (int i = 0; i < pers.Length; i++)
{
pers[i] = new Personne(ligneLue);
}
}

aLire.Close();

}

static void Afficher(Personne[] pers, int nbPers, string message)
{
Console.WriteLine("Contenu du tableau {0} :", message);
for (int i = 0; i < nbPers; i++)
{
pers[i].Afficher();
}
}


static void Main(string[] args)
{
const int max = 32;
Personne[] pers = new Personne[max];
int nbPers = pers.Length;

LireFichier("met_h12.txt", pers);
Afficher(pers, nbPers, "apres lecture du fichier");

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

}
}


When I print it, I get
0
0
0
0
0
0
0
0
0
0

my class array is empty for some reason



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.