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!
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.
An enumeration is a data type that consists of a set of named values that represent integral constants, known as enumeration constants. An enumeration is also referred to as an enumerated type because you must list (enumerate) each of the values in creating a name for each of them.
Enums are used when we know all possible values at compile time, such as choices on a menu, rounding modes, command-line flags, etc. It is not necessary that the set of constants in an enum type stay fixed for all time. A Java enumeration is a class type.
The first member of an enum will be 0, and the value of each successive enum member is increased by 1. You can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.
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 forint
,uint
,long
, andulong
.
And because operations on integral types are generally allowed on enumeration you can use ~
with enums backed with types listed above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With