Erreur en c#
oumaima94
Messages postés
7
Statut
Membre
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour, j'ai réaliser un devoir en c# d'une application de gestion de projets,des étudiants et leur encadrant après la compilation du programme un message d'erreur s'affiche "Assignation effectué à la même variable.souhaitiez vous assignez à un autre élément" j'ai pas compris le message d'erreur et aussi je sais pas le résoudre car je suis débutante en c# . J'attends vos réponses
A voir également:
- Erreur en c#
- Iptv erreur de lecture - Forum TV & Vidéo
- Erreur 0x80070643 - Accueil - Windows
- Erreur 0x80070643 Windows 10 : comment résoudre le problème de la mise à jour KB5001716 - Accueil - Windows
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
- Erreur 4201 france tv ✓ - Forum Réseaux sociaux
3 réponses
Bonsoir
pour être sûr, il faudrait que tu nous montres le code ou cette erreur apparait, mais ce type d'erreur arrive en général quand tu écris qu'une variable égale à elle-même, par exemple
pour être sûr, il faudrait que tu nous montres le code ou cette erreur apparait, mais ce type d'erreur arrive en général quand tu écris qu'une variable égale à elle-même, par exemple
int toto = 1; toto = toto;//ici assignation à la même variable
*
-
-
- Voici le code:*******
-
-
using System;
using System.Collections.Generic;
using System.Linq;!
using System.Text;
using System.Threading.Tasks;
namespace devoir
{
class Enseignant
{
private int code;
private string nom;
private string prenom;
private string sexe;
private int age;
private String specialite;
public void SetCode( int code)
{
code = code;
}
public int GetCode()
{
return code;
}
public void SetNom (String nom)
{
nom = nom;
}
public String GetNom ()
{
return nom;
}
public void SetPrenom (String prenom)
{
prenom = prenom;
}
public String GetPrenom()
{
return prenom;
}
public void SetSexe (String sexe)
{
sexe = sexe ;
}
public String GetSexe ()
{
return sexe;
}
public void SetAge (int age)
{
age = age ;
}
public int GetAge ()
{
return age;
}
public void SetSpecialite (String specialite )
{
specialite = specialite ;
}
public String GetSpecialite ()
{
return specialite;
}
public Enseignant() { }
public Enseignant( int code,string nom,string prenom,string sexe,int age,string specialite)
{
}
public virtual void Affichage()
{
Console.WriteLine ("Code: "+code+" Nom: "+nom+" Prenom "+prenom+" Sexe: "+sexe+" Age: "+age+" Specilité: "+specialite+"");
}
}
}
//////
class Etudiant
{
private string nom;
private string prenom;
private int niveau;
public void SetNom(String nom)
{
nom = nom;
}
public String GetNom()
{
return nom;
}
public void SetPrenom(String prenom)
{
prenom = prenom;
}
public String GetPrenom()
{
return prenom;
}
public void SetNiveau(int niveau)
{
niveau = niveau;
}
public int GetNiveau()
{
return niveau;
}
public Etudiant() { }
public Etudiant(string nom, string prenom, int niveau)
{
}
public void Affichage()
{
Console.WriteLine(" Nom: " + nom + " Prenom " + prenom + " Niveau : " + niveau + "");
}
}
}
///
class Projet
{
private int codeprojet;
private string sujet;
private DateTime datedebut;
private DateTime datefin;
public void SetCodeprojet(int codeprojet)
{
codeprojet = codeprojet;
}
public int GetCodeprojet()
{
return codeprojet;
}
public void SetSujet(String sujet)
{
sujet = sujet;
}
public String GetSujet()
{
return sujet;
}
public void SetDatedebut(DateTime datedebut)
{
datedebut = datedebut;
}
public DateTime GetDatedebut()
{
return datedebut;
}
public void SetDatefin(DateTime datefin)
{
datefin = datefin;
}
public DateTime GetDatefin()
{
return datefin;
}
public Projet() { }
public Projet(int codeprojet, string sujet, DateTime datedebut, DateTime datefin)
{
}
public void Affichage()
{
Console.WriteLine(" Codeprojet: " + codeprojet + " Sujet" + sujet + " Date de debut : " + datedebut + " Date fin: " + datefin + "");
}
}
}//////
class Encadrant : Enseignant
{
private string nomprojet;
private DateTime dateencadrement;
public void SetNomprojet(string nomprojet)
{
nomprojet = nomprojet;
}
public string GetNomprojet()
{
return nomprojet;
}
public void SetDateencadrement(DateTime dateencadrement)
{
dateencadrement = dateencadrement;
}
public DateTime GetDateencadrement()
{
return dateencadrement;
}
public Encadrant() : base() { }
public Encadrant (string nomprojet,DateTime dateencadrement)
: base(14, "rachid", "salim", "masculin", 21, "ingénieur")
{
}
public override void Affichage()
{
base.Affichage();
}
}
}
////////
class Program
{
static void Main(string[] args)
{
Enseignant enseignant = new Enseignant();
System.Console.WriteLine("entrer le codeidentifient svp: ");
int a = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Nom svp: ");
String b = Console.ReadLine();
System.Console.WriteLine("entrer le Prenom svp: ");
String c = Console.ReadLine();
System.Console.WriteLine("entrer le sexe svp: ");
String d = Console.ReadLine();
System.Console.WriteLine("entrer l Age svp: ");
int e = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer la specialite svp: ");
string f = Console.ReadLine();
enseignant.Affichage();
Etudiant etudiant = new Etudiant();
System.Console.WriteLine("entrer le codeetudiant svp: ");
int co = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Nom svp: ");
String no = Console.ReadLine();
System.Console.WriteLine("entrer le Prenom svp: ");
String pr = Console.ReadLine();
System.Console.WriteLine("entrer le niveau svp: ");
int nv = int.Parse(Console.ReadLine());
etudiant.Affichage();
Projet projet = new Projet();
System.Console.WriteLine("entrer le codeprojet svp: ");
int cp = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Sujet svp: ");
String sj = Console.ReadLine();
System.Console.WriteLine("entrer la date de debut svp: ");
DateTime dt = DateTime.Parse(Console.ReadLine());
System.Console.WriteLine("entrer la date de fin: ");
DateTime df = DateTime.Parse(Console.ReadLine());
projet.Affichage();
Encadrant encadrant = new Encadrant();
System.Console.WriteLine("entrer le Nom de projet svp: ");
String np = Console.ReadLine();
System.Console.WriteLine("entrer la date de encadrement svp: ");
DateTime de = DateTime.Parse(Console.ReadLine());
encadrant.Affichage();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;!
using System.Text;
using System.Threading.Tasks;
namespace devoir
{
class Enseignant
{
private int code;
private string nom;
private string prenom;
private string sexe;
private int age;
private String specialite;
public void SetCode( int code)
{
code = code;
}
public int GetCode()
{
return code;
}
public void SetNom (String nom)
{
nom = nom;
}
public String GetNom ()
{
return nom;
}
public void SetPrenom (String prenom)
{
prenom = prenom;
}
public String GetPrenom()
{
return prenom;
}
public void SetSexe (String sexe)
{
sexe = sexe ;
}
public String GetSexe ()
{
return sexe;
}
public void SetAge (int age)
{
age = age ;
}
public int GetAge ()
{
return age;
}
public void SetSpecialite (String specialite )
{
specialite = specialite ;
}
public String GetSpecialite ()
{
return specialite;
}
public Enseignant() { }
public Enseignant( int code,string nom,string prenom,string sexe,int age,string specialite)
{
}
public virtual void Affichage()
{
Console.WriteLine ("Code: "+code+" Nom: "+nom+" Prenom "+prenom+" Sexe: "+sexe+" Age: "+age+" Specilité: "+specialite+"");
}
}
}
//////
class Etudiant
{
private string nom;
private string prenom;
private int niveau;
public void SetNom(String nom)
{
nom = nom;
}
public String GetNom()
{
return nom;
}
public void SetPrenom(String prenom)
{
prenom = prenom;
}
public String GetPrenom()
{
return prenom;
}
public void SetNiveau(int niveau)
{
niveau = niveau;
}
public int GetNiveau()
{
return niveau;
}
public Etudiant() { }
public Etudiant(string nom, string prenom, int niveau)
{
}
public void Affichage()
{
Console.WriteLine(" Nom: " + nom + " Prenom " + prenom + " Niveau : " + niveau + "");
}
}
}
///
class Projet
{
private int codeprojet;
private string sujet;
private DateTime datedebut;
private DateTime datefin;
public void SetCodeprojet(int codeprojet)
{
codeprojet = codeprojet;
}
public int GetCodeprojet()
{
return codeprojet;
}
public void SetSujet(String sujet)
{
sujet = sujet;
}
public String GetSujet()
{
return sujet;
}
public void SetDatedebut(DateTime datedebut)
{
datedebut = datedebut;
}
public DateTime GetDatedebut()
{
return datedebut;
}
public void SetDatefin(DateTime datefin)
{
datefin = datefin;
}
public DateTime GetDatefin()
{
return datefin;
}
public Projet() { }
public Projet(int codeprojet, string sujet, DateTime datedebut, DateTime datefin)
{
}
public void Affichage()
{
Console.WriteLine(" Codeprojet: " + codeprojet + " Sujet" + sujet + " Date de debut : " + datedebut + " Date fin: " + datefin + "");
}
}
}//////
class Encadrant : Enseignant
{
private string nomprojet;
private DateTime dateencadrement;
public void SetNomprojet(string nomprojet)
{
nomprojet = nomprojet;
}
public string GetNomprojet()
{
return nomprojet;
}
public void SetDateencadrement(DateTime dateencadrement)
{
dateencadrement = dateencadrement;
}
public DateTime GetDateencadrement()
{
return dateencadrement;
}
public Encadrant() : base() { }
public Encadrant (string nomprojet,DateTime dateencadrement)
: base(14, "rachid", "salim", "masculin", 21, "ingénieur")
{
}
public override void Affichage()
{
base.Affichage();
}
}
}
////////
class Program
{
static void Main(string[] args)
{
Enseignant enseignant = new Enseignant();
System.Console.WriteLine("entrer le codeidentifient svp: ");
int a = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Nom svp: ");
String b = Console.ReadLine();
System.Console.WriteLine("entrer le Prenom svp: ");
String c = Console.ReadLine();
System.Console.WriteLine("entrer le sexe svp: ");
String d = Console.ReadLine();
System.Console.WriteLine("entrer l Age svp: ");
int e = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer la specialite svp: ");
string f = Console.ReadLine();
enseignant.Affichage();
Etudiant etudiant = new Etudiant();
System.Console.WriteLine("entrer le codeetudiant svp: ");
int co = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Nom svp: ");
String no = Console.ReadLine();
System.Console.WriteLine("entrer le Prenom svp: ");
String pr = Console.ReadLine();
System.Console.WriteLine("entrer le niveau svp: ");
int nv = int.Parse(Console.ReadLine());
etudiant.Affichage();
Projet projet = new Projet();
System.Console.WriteLine("entrer le codeprojet svp: ");
int cp = int.Parse(Console.ReadLine());
System.Console.WriteLine("entrer le Sujet svp: ");
String sj = Console.ReadLine();
System.Console.WriteLine("entrer la date de debut svp: ");
DateTime dt = DateTime.Parse(Console.ReadLine());
System.Console.WriteLine("entrer la date de fin: ");
DateTime df = DateTime.Parse(Console.ReadLine());
projet.Affichage();
Encadrant encadrant = new Encadrant();
System.Console.WriteLine("entrer le Nom de projet svp: ");
String np = Console.ReadLine();
System.Console.WriteLine("entrer la date de encadrement svp: ");
DateTime de = DateTime.Parse(Console.ReadLine());
encadrant.Affichage();
}
}
}
| EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI Merci d'y penser dans tes prochains messages. |
En regardant rapidement, j'ai vu :
specialite = specialite ;
Nommer un paramètre comme un attribut d'objet, c'est pas malin ...
Essayes de préfixer le nom des variable en fonction de leur portée par exemple :
l Locale
p Paramètre
o Objet
...
Ce qui pourrait donner :
oSpecialite = pSpecialite ;
Ce qui évite les soucis de ce genre.
specialite = specialite ;
Nommer un paramètre comme un attribut d'objet, c'est pas malin ...
Essayes de préfixer le nom des variable en fonction de leur portée par exemple :
l Locale
p Paramètre
o Objet
...
Ce qui pourrait donner :
oSpecialite = pSpecialite ;
Ce qui évite les soucis de ce genre.