Skip to content
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

Open
batibot323 opened this issue Feb 14, 2020 · 2 comments
Open

[Reference] Add new reference document: enums.md #699

batibot323 opened this issue Feb 14, 2020 · 2 comments
Labels
leave-open status/help-wanted Extra attention is needed type/new-reference-doc Add a new reference document

Comments

@batibot323
Copy link
Contributor

batibot323 commented Feb 14, 2020

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 the enum first with its possible values then, you can use the defined enum to give your variables that type. That variable can now only have possible values as defined by that enum

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 type Month and name it firstMonth. The compiler, or your tool will only allow you to set firstMonth to one of the possible values.

Here's an example using C#:

public enum Month
{
    January,
    February,
    ...,
    December
}

public class EnumConversionExample
{
    public static void Main()
    {
        Month firstMonth = Month.January; // First month of the year is January
        Console.WriteLine(firstMonth); // Prints out `January`

        firstMonth = "Hello World!"; // Errors out!
    }
}

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

  • Create the document using master/reference/concepts/enums.md
  • Add a link to the reference document in the reference README at master/reference/concepts/README.md.

Help

If you have any questions while adding the reference document, please post the questions as comments in this issue.

@batibot323 batibot323 added type/new-reference-doc Add a new reference document status/help-wanted Extra attention is needed labels Feb 14, 2020
@ghost
Copy link

ghost commented Mar 2, 2020

@batibot323 howdy! Is this specific to the C# track? If so, can you add that track label?

@batibot323
Copy link
Contributor Author

@batibot323 howdy! Is this specific to the C# track? If so, can you add that track label?

Hi @efx ! This was supposed to go to the reference folder that encompasses all languages. Link to folder.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
leave-open status/help-wanted Extra attention is needed type/new-reference-doc Add a new reference document
Projects
None yet
Development

No branches or pull requests

2 participants