Maybe a bit silly question, but in one of my projects I needed an enum and I suddenly wondered what would
be the best place for it to write it in a file. Should it be in a .cs file of his own or could I place it in the
class file where it is mostly used?
Thanks in advance for any enlightment.

Recommended Answers

All 3 Replies

For smaller projects I place enums in a project-level Enumerations.cs file. For larger projects I tend to break things down into folders where each folder holds related stuff and might have its own Enumerations.cs file.

For tiny projects or strongly self-contained classes where only the class needs access to it, I might place the enum in the same file as the class.

The important thing to do is make sure that the structure of your files makes it clear how much visibility an enum has. Putting it in the same file as the class that uses it the most strikes me as a confusing file structure.

Thanks decepticon. The way you exploained it seems the way to handle it.

enum is utilized to make numeric constants in .NET schema. All part of enum are of enum sort. There must be a numeric worth for every enum sort. The default underlying kind of the specification components is int. Naturally, the first enumerator has the quality 0, and the estimation of every progressive enumerator is expanded by 1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.