what's wrong with my code? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

what's wrong with my code?

chickenpoochickenpoo Posts: 1Member
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("
On 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
Sign In or Register to comment.