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

Your 2020 Plan. Learn 20 minutes a day for 20 days. Online courses from €9.99.

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

One thought on “Tilde (~) Symbol in the Enum definition in C#

Leave a Reply

Your email address will not be published. Required fields are marked *