0

I have the following:

public enum Size
{
    XXS,
    XS,
    S,
    M,
    L,
    XL,
    1XL, 
    2XL, 
    3XL, 
    4XL, 
    5XL, 
    6XL
}

The enum is for a DB and I need it to go into the DB in this format (nvarchar), I have not created this DB table.

Error 30 Type or namespace definition, or end-of-file expected

I know it is because there is a number at the beginning, is there anyway round this, other than doing a switch statement or something?

UPDATE:

This is for a Google Feed, they require the values to be provided as below, this is not our naming convention

Clare Barrington
  • 1,135
  • 1
  • 11
  • 28

3 Answers3

3

C# identifier names cannot begin with numerics. How about rendering the numbers as words? XL, TwoXL, ThreeXL, FourXL and so on?

Matt
  • 1,648
  • 12
  • 22
1

You cannot define an identifier name starts with a digit, first character must be a letter or an underscore.Here You are trying to overwrite the basic rule for defining an identifier. Let me remind you the rules once again:

  • An identifier is a sequence of letters,digits and underscore.
  • The first character Must be either a letter or an underscore
  • Keywords cannot be used as an identifiers, since it is reserved by the language compiler.

The Possible declarations for you:

Start with an underscore

public enum Size
{
    _XXS,           
    _1XL,
}

Use words instead for digits

public enum Size
{
    _XXS,           
    oneXL,
}
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
0

Have a look here, maybe you can work around this issue with DataAnnotations. See this solution: How to get the Display Name Attribute of an Enum member via MVC razor code?

Community
  • 1
  • 1
Thomas Voß
  • 1,145
  • 8
  • 20