What does "~" mean before listing

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’t understand. "~" - Is that a mistake? As far as I remember, "~" is placed before the destructors. But this is an enumeration. And this code compiled!

+5
source share
1 answer

It is a bitwise negation operator.

~ Operator (link to C #)

The operator ~performs a bitwise addition to the operand, which has the effect of reversing each bit. Bitwise complement operators are predefined for int, uint, longand ulong.

And since operations with integral types are usually allowed when enumerating, you can use ~with enumerations supported by the types listed above.

+6

All Articles