Vote count:
0
While brushing up on enums, I ran across the following at MSDN Developer Network's site.
Usually it is best to define an enum directly within a namespace so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.
This makes sense as I need all of my enums to be available to all of the classes in my project. However, I can't seem to find any examples. Here's what I have so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myNamespace
{
enum foo {A, B, C, D}
enum foo2 {E, F, G, H}
class Myclass
{
magicHappens();
}
}
I am wondering if I need to include the enum in EVERY class I include in this namespace, or if defining it in only one class will pull those enum definitions into the project as a whole at compile time? And is there a specific class it needs to be in? Or is it best practice to just create a class that does nothing but define namespace-level enums?
Any tips would be appreciated.
Aucun commentaire:
Enregistrer un commentaire