C# enum

enum data type is a group of constants with key and value.

public enum Char_Direction
{
Center = 0,
OutSide = 1,
ClockWise = 2,
AntiClockWise = 3
}
Char_Direction.OutSide; //1

If the value starts from 0, the values may not needed.
public enum CaretMode { InsertMode, OverwriteMode }
//is equal to
public enum CaretMode { InsertMode=0, OverwriteMode=1 }

You may specify the start value:
public enum Char_Direction
{
Center = 2, OutSide, ClockWise, AntiClockWise
}
//is equal to
public enum Char_Direction
{
Center = 2, OutSide = 3, ClockWise = 4, AntiClockWise = 5
}

enum to string:
Char_Direction.OutSide.ToString(); //OutSide



endmemo.com © 2024  | Terms of Use | Privacy | Home