What does "~" mean before enums

c#, enums, syntax

Solution

It's bitwise negation operator.

~ Operator (C# Reference)

The `~` operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. Bitwise complement operators are predefined for `int`, `uint`, `long`, and `ulong`.

And because operations on integral types are generally allowed on enumeration you can use `~` with enums backed with types listed above.

Problem

Today I see this code: ``` ViewBag.country = from p in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures) select new SelectListItem { Text = p.EnglishName, Value = p.DisplayName }; ``` And I can not understand. "~" - This is a mistake? As far as I remember, "~" is placed before the destructors. But this is enum. And this code compiled!

Original source

Related problems