2

So I am working on a school project and I should make saves of different kind of people profils and jobs offers profils, so I got my enum "Skills" which correspond to the differents certificate, and I I got in a profil argument a list of Skills.

I'm actually trying to load a new profil from a text file and I know how it's organized, I have for the first line the password, then the name etc etc, until the lines 7 or 6 (depending if you begin counting to 0 or 1), from there there is skills name written, and I'm actually getting them as a string, so I'm trying to convert them in Skills enum type with the "Enum.Parse(Type EnumType, string Value);"

Here is my problem, it says that "Skills" is an unavailable type and I don't really understand why even after trying to read the microsoft documentation, I founded a site explaining how to convert from a string to an enum type and they made as I did so if anyone can help me seing clear I would be grateful. Thanks you.

    {
        Baccalauréat,
        FormationPremierSecours,
        PréventionEtSecoursCiviquesN1,
        PremierSecoursEnEquipeN2,
        BrevetNationalDeSécuritéEtDeSauvetage,
        SauveteurSecouristeDuTravail,
        BAFA,
        BAFD,
        BASE,
        BSB,
        CAPaccessoiristeRealisateur,
        CAPaccordeurPiano,
        CAPagentAccueilConduiteRoutiereTransportVoyageur,
        CAPagentAssainissementCollecteDéchetsLiquidesSpéciaux,
        CAPagentEntreposageMessagerie,
        CAPagentQualitéDeLeau,
        CAPagentDePreventionMediation,
        CAPagentDeSécurité,
        CAPpolyvalentRestauration,
        CAPVerificaterExtincteurs,
        CAParmurerieFabricationEtReparation,
        CAPartEtTechniquesBijouterieJoaillerieOptionJoaillerie,
        CAPartEtTechniquesBijouterieJoaillerieOptionSertissage,
        CAPartEtTechniquesBijouterieJoaillerieOptionFinition,
        CAPartDeLaBroderie,
        CAPartDentelle,
        CAPArtsReliure,
        CAPartBoisMarqueteur,
        CAPartBoisSculpteurOrnemaniste
    }

public static void RecupProfile(profil profile)
        {
            string mdp;
            string Name;
            string Description;
            string Mail;
            uint Age;
            string PExperiences;
            string skill;
            Skills diplome;
            List<Skills> Diplomes = new List<Skills>();
            string Path = "..\\profilsave\\" + profile.GetNickname() + ".txt";
            string text = File.ReadAllText(Path);
            string[] lines = text.Split(Environment.NewLine);

            uint borne = (uint) lines.Length;
            
            mdp = lines[0];
            Name = lines[1];
            Description = lines[2];
            Mail = lines[3];
            Age = Convert.ToUInt32(lines[4]);
            PExperiences = lines[5];
            uint i = 6;
            while (i< borne)
                
            {
                
                skill = lines[i];
                if(Enum.IsDefined(typeof(Skills), skill))
                {
                    diplome = Enum.Parse(Skills, skill); //Here is the problem
                    
                    
                }
                Diplomes.Add(diplome);
                i += 1;
            }
        }

4
  • 1
    it says that "Skills" is an unavailable type For the life of me I don't understand why people paraphrase error messages (poorly). Pretty sure it doesn't actually say that. Please cut and paste the actual error text. It's less typing for you and won't leave the rest of us scratching our heads wondering what you're talking about. Commented Jun 19, 2021 at 1:50
  • 1
    @JohnWu maybe the error is french and they're adhering to the "SO shall be in English" by providing an approximation 🤷‍♀️ Commented Jun 19, 2021 at 6:26
  • Enums should not have a plural name if they are not [Flags] Commented Jun 19, 2021 at 6:28
  • What is that first list? It seems not to have a name? Commented Jun 19, 2021 at 9:58

2 Answers 2

4

Try this

diplome = (Skills)Enum.Parse(typeof(Skills), skill);

or this

diplome = Enum.Parse<Skills>(skill);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you, the first one didn't worked but the second does, many thx, btw do you know how I can close a thread since the problem is resolved?
-1

Just casting Skills type

Enum.Parse(typeof(Skills), skill);

1 Comment

Except you didn't cast it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.