none
Convert from VB.net to C# Enumeration select case RRS feed

  • Question

  • Hi All

    I need to connvert in C# the following code (I use WinForm)

    In a VB.net  Library there is an Enumeration of texgBox TAGs  in a Module (MOD1)

     

    Public Module Mod1

    Public Enum TagList AN '- accetta caratteri stampabili AA '- accetta solo lettere DB '- nome per database NIP '- accetta solo numeri interi positivi NI '- accetta numeri interi positivi e negativi NDP '- accetta numeri decimali solo positivi ND '- accetta numeri decimali e interi positivi o negativi end Enum

    End Module

    Then in a Sub in C# I have to check a Tag value from TextBox (MyTag in the followin code)

    How to convert in C# the following  VB.net Code ?

    Dim EnumValTag = DirectCast([Enum].Parse(GetType(TagList), MyTag), TagList)
    
    Select Case EnumValTag
                   
           Case TagList.AN, TagList.AA
                      
                ' do something
             
          
            Case Else 
                 ' do something else
                       
    End Select
    
      
    Thanks for Help 

    Wednesday, November 14, 2018 5:02 PM

Answers

  • Hello, 

    switch(EnumValTag)
    {               
        case TagList.AN: 
        case TagList.AA:
                      
                // do something
             break;
          
        default:
                //  do something else
             break;
    }


    Sincerely, Highly skilled coding monkey.

    • Marked as answer by Claudio111 Wednesday, November 14, 2018 5:20 PM
    Wednesday, November 14, 2018 5:07 PM

All replies

  • Hello, 

    switch(EnumValTag)
    {               
        case TagList.AN: 
        case TagList.AA:
                      
                // do something
             break;
          
        default:
                //  do something else
             break;
    }


    Sincerely, Highly skilled coding monkey.

    • Marked as answer by Claudio111 Wednesday, November 14, 2018 5:20 PM
    Wednesday, November 14, 2018 5:07 PM
  • thank you

    Wednesday, November 14, 2018 5:21 PM
  • even if I should write 

     case Mod1.TagList.AN: 

    if Mod1 in in another Project

    Wednesday, November 14, 2018 5:23 PM