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
VulpesPosted Oct 25, 2012, 9:53 AM
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.
Sandeep Singh ShekhawatPosted Oct 25, 2012, 9:47 AM
We can't declare and define an Enum inside a method or Event.
Thanks
Sandeep
Matt HigginsPosted Oct 25, 2012, 9:02 AM
{
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?
Neha SharmaPosted Oct 25, 2012, 8:56 AM
Shivanand ArurPosted Oct 25, 2012, 8:48 AM
Matt HigginsPosted Oct 25, 2012, 8:47 AM
Sorry, I uploaded the Source Code by clicking on Browse. Is there another way I should be doing it?
Shivanand ArurPosted Oct 25, 2012, 8:19 AM
Thanks!!!