enum question

This is a discussion on enum question within the C# Programming forums, part of the General Programming Boards category; I am parsing a XML file. I have enum:ed some things like this: Code: enum NeighbourhoodDogs {Felix, Fido, Boo} In ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    41

    enum question

    I am parsing a XML file. I have enum:ed some things like this:

    Code:
    enum NeighbourhoodDogs {Felix, Fido, Boo}
    In the XML file I later get records like this:
    Code:
    <Dog Name="Boo" Weight="54.30" />
    Is there a way to use the enum here to put Boos weight in an array somehow, kind of like this:

    Code:
    dogweights[Boo] = w;
    // w is an extracted value from the XML file

    How do I do the mapping from string to enum or do I need to use a hashmap here?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    string X = "Fido";
    NeighbourhoodDogs Y = System.Enum.Parse(typeof(NeighbourhoodDogs), X, true);
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    41
    Thanks.... again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Question on Enum
    By markcls in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 08:19 AM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  4. Enum question
    By Bill 101 in forum C Programming
    Replies: 4
    Last Post: 10-30-2002, 11:33 PM
  5. enum question
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 12-29-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21