What are the differences between enum and class ?
Dec 25, 2021
Hello everbody,
An enum, just like a class, have attributes and methods.
An Enum constants are always public static and final.
Some uses of enums are like month days, days, colors and more.
Basic enum DescriptionAttribute sample, following,
public enum Colors{[Description("Red")]Red,[Description("White")]White,[Description("Blue")]Blue,[Description("Green")]Green}
Basic enum method sample, following,
using System;using System.ComponentModel;namespace EnumApp{public enum Colors{ [Description("Red")] Red, [Description("White")] White, [Description("Blue")] Blue, [Description("Green")] Green}class Program{ static void Main(string[] args) { String color = "White"; switch(color) { case "Red": Console.WriteLine("Color is " + Colors.Red); break; case "White": Console.WriteLine("Color is " + Colors.White); break; case "Blue": Console.WriteLine("Color is " + Colors.Blue); break; case "Green": Console.WriteLine("Color is " + Colors.Green); break; default: Console.WriteLine($"{color} is a unknown color by system"); break; } Console.ReadLine(); } }}
Good luck.