IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Erreur : does not contain a definition


Sujet :

C#

  1. #1
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2017
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Mars 2017
    Messages : 176
    Points : 58
    Points
    58
    Par défaut Erreur : does not contain a definition
    Bonjour,

    J'essaie de compiler le code ci-dessous mais j'obtiens une erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    using System;
     
    public class Song
    {
        private string name;
        public Song nextSong { get; set; }
     
        public Song(string name)
        {
            this.name = name;
        }
     
        public void setNextSong(Song nextSong) 
        {
            this.nextSong = this.nextSong;
        }
     
        public bool isRepeatingPlaylist()
        {
            Song slowStep = this;
            Song fastStep = this;
     
            while (((fastStep != null) && (fastStep.nextSong != null))) 
            {
                slowStep = slowStep.nextSong;
                fastStep = fastStep.nextSong.nextSong;
     
                if ((slowStep == fastStep))
                {
                    return true;
                }
     
            }
     
                return false;
         }
     
        public static void Main(string[] args)
        {
            Song first = new Song("Hello");
            Song second = new Song("Eye of the tiger");
     
            first.nextSong = second;
            second.nextSong = first;
     
            Console.WriteLine(first.IsRepeatingPlaylist());
        }
    }
    L'erreur est la suivante :


    Compiler output:
    PlaylistTest.cs(15,30): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(21,30): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(26,47): error CS1061: 'Song' does not contain a definition for 'IsRepeatingPlaylist' and no extension method 'IsRepeatingPlaylist' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(35,15): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(36,16): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(37,31): error CS1061: 'Song' does not contain a definition for 'IsRepeatingPlaylist' and no extension method 'IsRepeatingPlaylist' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(65,15): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(66,15): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(67,15): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(68,15): error CS1061: 'Song' does not contain a definition for 'NextSong' and no extension method 'NextSong' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    PlaylistTest.cs(69,31): error CS1061: 'Song' does not contain a definition for 'IsRepeatingPlaylist' and no extension method 'IsRepeatingPlaylist' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    Playlist.cs(46,33): error CS1061: 'Song' does not contain a definition for 'IsRepeatingPlaylist' and no extension method 'IsRepeatingPlaylist' accepting a first argument of type 'Song' could be found (are you missing a using directive or an assembly reference?)
    Merci pour votre aide

  2. #2
    Membre chevronné
    Avatar de PixelJuice
    Homme Profil pro
    Ingénieur .NET & Game Designer
    Inscrit en
    Janvier 2014
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur .NET & Game Designer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 640
    Points : 2 149
    Points
    2 149
    Par défaut
    Bonjour,

    Il aurait été intéressant de voir le code de PlaylistTest aussi mais dans ton cas pas besoin de l'avoir, les erreurs sont très parlantes :

    Tu appelles des variables et des méthodes avec une majuscule alors que tu les a définies sans majuscules :

    Petit rappel: En C#, on mets toujours une majuscule au début d'un nom de méthode, et c'est valable aussi pour les variables qui sont publiques.

  3. #3
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2017
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Mars 2017
    Messages : 176
    Points : 58
    Points
    58
    Par défaut
    Merci beaucoup. ça compile.

    Code corrigé :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    using System;
     
    public class Song
    {
        private string Name;
        public Song NextSong { get; set; }
     
        public Song(string name)
        {
            this.Name = name;
        }
     
        public void setNextSong(Song NextSong) 
        {
            this.NextSong = this.NextSong;
        }
     
        public bool IsRepeatingPlaylist()
        {
            Song slowStep = this;
            Song fastStep = this;
     
            while (((fastStep != null) && (fastStep.NextSong != null))) 
            {
                slowStep = slowStep.NextSong;
                fastStep = fastStep.NextSong.NextSong;
     
                if ((slowStep == fastStep))
                {
                    return true;
                }
     
            }
     
                return false;
         }
     
        public static void Main(string[] args)
        {
            Song first = new Song("Hello");
            Song second = new Song("Eye of the tiger");
     
            first.NextSong = second;
            second.NextSong = first;
     
            Console.WriteLine(first.IsRepeatingPlaylist());
        }
    }

  4. #4
    Membre chevronné
    Homme Profil pro
    edi
    Inscrit en
    Juin 2007
    Messages
    899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : edi

    Informations forums :
    Inscription : Juin 2007
    Messages : 899
    Points : 1 916
    Points
    1 916
    Par défaut
    Citation Envoyé par Jinkas99 Voir le message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        public void setNextSong(Song NextSong) 
        {
            this.NextSong = this.NextSong;
        }
    Ça ne sert strictement à rien.

  5. #5
    Membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2017
    Messages
    176
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Mars 2017
    Messages : 176
    Points : 58
    Points
    58
    Par défaut
    Effectivement je me suis trompé.

    Merci pour votre remarque.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 26/08/2013, 13h55
  2. Erreur "file does not contain valid xml"
    Par moustaf_26 dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 01/01/2013, 16h53
  3. LookUpDispatchAction Erreur does not contain specified method
    Par bruno.getJava() dans le forum Struts 1
    Réponses: 9
    Dernier message: 07/12/2010, 11h54
  4. Réponses: 2
    Dernier message: 28/03/2007, 22h25
  5. Réponses: 1
    Dernier message: 10/05/2006, 12h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo