471,354 Members | 1,293 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

Using the # sign

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

Feb 14 '06 #1
5 1282
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike" <am******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Feb 14 '06 #2
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.

"Mike" <am******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Feb 14 '06 #3
enum Notes
{
A,
Asharp,
B,
C,
Csharp,
D,
Dsharp,
E,
F,
Fsharp,
G,
Gsharp
}

Feb 14 '06 #4
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

Mike wrote:
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


Feb 14 '06 #5
Thanks All
I think the ASharp syntax should work.And Clint, I feel the same way.
Mike

Feb 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by tarmat | last post: by
4 posts views Thread by thx606 | last post: by
4 posts views Thread by Kun | last post: by
reply views Thread by thomas.mertes | last post: by
20 posts views Thread by Ravikiran | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.