Hi I'm trying to declar a static enum like so:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace Lds.CM.MyApp.Controllers { public class MenuBarsController : Controller { // Menu Bar enums public static enum ProfileMenuBarTab { MainProfile, Edit, photoGallery } public ActionResult cpTopMenuBar(string tabSelected) { ...
" But I'm getting the following error: "The modifier 'static' is not valid for this item." I know it's something simple but I can't seem to see the problem. Much thanks!
An enum can, just like a class , have attributes and methods. The only difference is that enum constants are public , static and final (unchangeable - cannot be overridden). An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).
static enum direction {UP,DOWN,RIGHT,LEFT}; This declares an enumerated type with the tag name directions , and also defines a number of enumeration constants and their values. The static storage-class is meaningless here, because you are not defining (allocating storage) for an object.
The keyword 'enum' is used to declare new enumeration types in C and C++. Following is an example of enum declaration. // The name of enumeration is "flag" and the constant // are the values of the flag.
Every enum constant is static.
Enums are types, not variables. Therefore they are 'static' per definition, you dont need the keyword.
public enum ProfileMenuBarTab { MainProfile, Edit, PhotoGallery }
Take out static
.
Enums are types, not members; there is no concept of a static or non-static enum.
You may be trying to make a static field of your type, but that has nothing to do with the type declaration.
(Although you probably shouldn't be making a static field)
Also, you should not make public
nested types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With