This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
[Reference] Add new reference document: enums.md #699
Labels
leave-open
status/help-wanted
Extra attention is needed
type/new-reference-doc
Add a new reference document
This issue describes how to add a new reference document: <enums.md>.
Description
Using
enums
is a great way to limit the possible values of a variable. It allows you to create your own variable type and define its set of allowable values. You'd have to define theenum
first with its possible values then, you can use the definedenum
to give your variables that type. That variable can now only have possible values as defined by thatenum
For example, you're working with months, you would want to create an
enum
called Month, and set its allowable values to the 12 possible months. Then you can create a variable of typeMonth
and name it firstMonth. The compiler, or your tool will only allow you to setfirstMonth
to one of the possible values.Here's an example using C#:
This is mostly used to help us read and write our code. It gets rid of magic numbers, wherein you assign a number to a status (much like error 404). It helps in removing the cognitive load of having to translate the number to something that's meaningful.
Resources to refer to
Blog post about Enums in general
C# documentation on Enums
Java documentation
Contributing
Help
If you have any questions while adding the reference document, please post the questions as comments in this issue.
The text was updated successfully, but these errors were encountered: