vb.net - How to have an integer string in an enum? -


i know proper enum:

private enum months   january = 1   february = 2   ... end enum 

however, want have enum string solely integers.

example:

private enum columncounts   01 = 5   02 = 4   03 = 40 end enum 

the 01, 02 , 03 strings. however, if put "01", [01] or 01, tells me expects end of enum , isn't valid statement. there way accomplish i'm missing? tried. 01.tostring(), wasn't option. :) , appreciated. thanks.

edit:

public class part    private enum columncounts     f01 = 39   end enum    public shared function validatecolumns(byref lstfields list(of string)) boolean     each colcount in [enum].getvalues(gettype(columncounts))       if colcount = "f" + lstfields(1)         'right here need compare count of list vs. value of enum.'         return true       end if     next      return false   end function end class 

essentially, didn't want put f in there, wanted 01. way called is:

select case (nrecordtype)   case "01"     ...   case "02"     ...   case "03"     return part.validatecolumns(_lstfields) end select 

because i'm not making instance of , not calling constructor, there's no way autopopulate dictionary. , don't want convert integer i'm not going array. in case value gets above 99 , next value a0. i'm trying think of easy future changes , backwards compatability. if need more explanations, let me know.

edit 2:

this i've done , think should work:

public class part    private shared columncounts dictionary(of string, integer) = new dictionary(of string, integer)    public shared function validatecolumns(byref lstfiels list(of string)) boolean     initializecolumndictionary()      return lstfields.count = columncounts(lstfields(1))   end function    private shared sub initializecolumndictionary()     columncounts.add("01", 39)   end sub end class 

i'm not @ point can test right can't verify it's going want to, doesn't give me error when build i'm crossing fingers.

integers alone not valid identifiers. why want call 01 identifier? prefix enum elements letter, , you're done:

i01, i02 ... 

edit per editing: declare static dictionary , populate it, if it's null, in static method:

private static void yourmethod()         {             if (columncounts == null)             {                 columncounts = new dictionary<string, int>();                 columncounts.add("01", 39);                 columncounts.add("02", 45);                 columncounts.add("03", 12);                 columncounts.add("04", 0);             }             }            private static dictionary<string, int> columncounts = null; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -