Using the # sign

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hello,
I have an enum that uses the # sign in a Constant and I'm getting
syntax errors. How do I excape this in my code.
enum Notes
{
A,
A#,
B,
C,
C#,
D,
D#,
E,
F,
F#,
G,
G#
}
Thanks
Mike
 
Mike,

The compiler will not allow this, since the identifer is invalid. You
will need to use ASharp, CSharp, etc, etc. Personally, I think that this is
more readable.

Hope this helps.
 
Enums must follow the same constraints that any variable or symbols follow.
If you cannot make a variable with that name then you cannot make an enum
value with that name.
 
enum Notes
{
A,
Asharp,
B,
C,
Csharp,
D,
Dsharp,
E,
F,
Fsharp,
G,
Gsharp
}
 
Like everyone else said, you can't use '#' as an enum value ...but
since you're doing something related to music, you can also do this ...

enum Notes
{
A
Bb
B
C
Db
D
Eb
E
F
Gb
G
Ab
}

Granted, I hate seeing Gb instead of F# in music scores, it does get
the point across :)

Clint
 
Thanks All
I think the ASharp syntax should work.And Clint, I feel the same way.
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top