Skip to content

Instantly share code, notes, and snippets.

@xCyborg
Created October 22, 2020 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xCyborg/fe08af560656b0c1193936bcea7fec0e to your computer and use it in GitHub Desktop.
Save xCyborg/fe08af560656b0c1193936bcea7fec0e to your computer and use it in GitHub Desktop.
Patterns like _enum_class_ and _singletons_
public class Planet // enum class
{
public static readonly Planet MERCURY = new Planet(1, "Mercury");
public static readonly Planet VENUS = new Planet(2, "Venus");
public static readonly Planet EARTH = new Planet(3, "Earth");
public static readonly Planet MARS = new Planet(4, "Mars");
public static readonly Planet JUPITER = new Planet(5, "Jupiter");
public static readonly Planet SATURN = new Planet(6, "Saturn");
public static readonly Planet URANNUS = new Planet(7, "Uranus");
public static readonly Planet NEPTUNE = new Planet(8, "Naptune");
public int ID => this.id;
public string Name => this.name;
private readonly int id;
private readonly string name;
private Planet(int id, string name)
{
this.id = id;
this.name = name;
}
}
@xCyborg
Copy link
Author

xCyborg commented May 30, 2021

            Planet myPlanet = Planet.EARTH;
            Console.WriteLine(myPlanet.ID);
            Console.WriteLine(myPlanet.Name);
            Console.ReadKey();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment