What is good practice in determining where enumerations and structures are listed?

Assuming that enumor is structnot nested within a particular class, i.e. it belongs to the project namespace, it must be defined in:

  • Own file
  • A general-purpose file is called Enums.csor Structs.cswhere all enums/ structsthat belong to the project namespace will be defined
  • Somewhere else...
+3
source share
4 answers

This Best Practices MSDN article does not provide recommendations on where to store enumeration definitions.

. , , . , , , , , , , .

- , , .

+5

, . , .

, . , . .

+6

= , . - Func Action, , Delegates.cs.

- , , . . ? , , , . ( , decimal DateTime ? Eek!)

EDIT: , : interop. Interop.cs Win32.cs... , , .

+6

. , xml doccomment , ... , , , .

, , ( , xml doccomment , ), .

, , , ( doccomment), , , . , , . , , , , ... , .

I think that there is also a very simple but practical reason for each type in its own file. They are very BEST to understand. If you wrap your enumerations and structures inside other types or save them in another file, sometimes (and don't assume that you and the people reading your code always have access to Visual Studio and all your rich tools), it can be quite complicated find the type you are looking for.

+2
source

Source: https://habr.com/ru/post/1709642/


All Articles