Subscribe to our YouTube Channel for more Videos

Tilde (~) Symbol in the Enum definition in C#


During a casual discussion with one of my friend , I came across a question on whether the tilde(~) symbol can be used in the enum definition as shown below.

public enum TypeData
{
    All = ~0,
    None = 0
}

Can tilde symbol be used as the enum values ? . Simple answer is Yes.

~0 results in the value -1

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.