Alex Rivera | Logout

Should enumerations be placed in a separate file or within another class?

Asked 2010-03-17T16:02:30.030
16

I currently have a class file with the following enumeration:

using System;

namespace Helper
{
    public enum ProcessType
    {
        Word = 0,
        Adobe = 1,
    }
}

Or should I include the enumeration in the class where it's being used?

I noticed Microsoft creates a new class file for DockStyle:

using System;
using System.ComponentModel;
using System.Drawing.Design;

namespace System.Windows.Forms
{
    public enum DockStyle
    {
        None = 0, 
        Top = 1,
        Bottom = 2,
        Left = 3,
        Right = 4,.
        Fill = 5,
    }
}
Edit
Report

1 Answer

29

If the enum is only relevant to one class, it may make sense to make it a nested type. If it could be used elsewhere, it makes sense to make it a top-level type.

answered 2010-03-17T16:05:08.703

Your Answer