Hi
I'm just trying to learn about enums.
For some reason I get an error:-
} expected
and also
Type or namespace definition, or end-of-file expected
I attached the basic code - I'm just wondering if I need to declare the enum as a type underneath.
Thanks to anyone who can help
Cheers
Matt
Loading

Shivanand ArurRank #920 · 2.3K reputationPosted Oct 25, 2012, 4:19 AM EDT
Thanks!!!
Matt Higgins32 reputationPosted Oct 25, 2012, 4:47 AM EDT
Sorry, I uploaded the Source Code by clicking on Browse. Is there another way I should be doing it?
Shivanand ArurRank #920 · 2.3K reputationPosted Oct 25, 2012, 4:48 AM EDT
Neha SharmaRank #569 · 4.3K reputationPosted Oct 25, 2012, 4:56 AM EDT
Matt Higgins32 reputationPosted Oct 25, 2012, 5:02 AM EDT
{
private void button1_Click(object sender, EventArgs e)private enum DayofWeek{
Sunday=1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
}
}
I've found the fault now - it doesn't like it when I put an enum command inside the button1_click method. I can declare it outside a method fine though. Anyone know why I'm not able to declare it in the button click event?
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Oct 25, 2012, 5:47 AM EDT
We can't declare and define an Enum inside a method or Event.
Thanks
Sandeep
VulpesRank #55 · 29.2K reputationPosted Oct 25, 2012, 5:53 AM EDT
A type declaration (class, struct, enum, delegate etc) can either stand on its own or it can be nested within another class or struct. It can't be nested within a method.
Here you're nesting the enum within your Form class and, as you've declared it to be private, it is not accessible outside that class.