none
Get Enum value when enum is numeric RRS feed

  • Question

  • Hi all,

    I have a problem getting the correct value of an enum:

    Let's say I have a enum like this

    <System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440"),  _
     System.SerializableAttribute(),  _
     System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://www.site.com")>  _
    Public Enum c_PersonType
        
        '''<comentarios/>
        <System.Xml.Serialization.XmlEnumAttribute("001")>  _
        Item001
        
        '''<comentarios/>
        <System.Xml.Serialization.XmlEnumAttribute("002")>  _
        Item002
        
        '''<comentarios/>
        <System.Xml.Serialization.XmlEnumAttribute("003")>  _
        Item003
    End Enum


    Now, my problem is that if I try to get the enum value I get the value based on the index of elements:

    person.Persontype = [Enum].Parse(GetType(c_PersonType), "001")

    I always get the "item002" value, so I assume that is reading the enum by index (zero based) and converts "001" to 1

    Any ideas?

    Thanks in advance


    G.Waters

    Wednesday, June 21, 2017 7:50 PM

Answers

  • Nevermind, I solved it like this:

    [Enum].Parse(GetType(c_PersonType), "Item001")

    :)


    G.Waters

    • Marked as answer by George Waters Wednesday, June 21, 2017 8:33 PM
    Wednesday, June 21, 2017 8:33 PM