The fixed values are called as Literal. Literal is a value which is used by the variables. Before C# 7.0 six types of literals are available that are an integer, Floating-point, Character, String, Null, Boolean literals. In C# 7.0 there is one more literal is added which is known as Binary Literal. The binary literal is used to store the binary value in a variable. And the binary literal is represented by 0b. Binary literals are mainly used for bitmasks.
var num = 0b10001
Here when the compiler sees 0b in the variable value, then it automatically treated this num as a binary literal. If you try to run this on the compilers below C# 7.0, then the compiler will throw an error because this feature is introduced in C# 7.0 so, it will only work on C# 7.0 and above compilers.
Value of Num1 is: 9 Value of Num2 is: 67 Char value of Num2 is: C
The concept of digit separator is introduced in C# 7.0. With the help of digit separator, you can separate the large number into small parts which makes your code more readable. Underscore(_) is used as a digit separator. When you use digit separator in your code they are simply ignored by the compiler, so the compiler does not print digit separators in the output like as shown in the below example.
X: 100000022200000202 Z: 10000000020 Num1: 1000110000000000 Num2: 33554432 Num3: 1000000000000000000 Num4: 103213629569
- C# | Literals
- C# Program to Convert a Binary String to an Integer
- How to Install and Setup Visual Studio for ASP.NET?
- C# | .NET Framework (Basic Architecture and Component Stack)
- C# | Boxing And Unboxing
- Difference between SortedList and SortedDictionary in C#
- C# | TrimStart() and TrimEnd() Method
- C# | Class and Object
- C# | Check if SortedSet and a specified collection share common elements
- C# | Check if HashSet and the specified collection contain the same elements
- C# | Check if a HashSet and a specified collection share common elements
- C# | Check if SortedSet and the specified collection contain the same elements
- C# | Jump Statements (Break, Continue, Goto, Return and Throw)
- Difference between Managed and Unmanaged code in .NET
- C# | Bitwise AND between the elements of BitArray
- C# | Add key and value into StringDictionary
- C# | Add the specified key and value into the ListDictionary
- C# | Adding the specified key and value into HybridDictionary
- C# | Add key and value into OrderedDictionary collection
- C# | Insert into OrderedDictionary with key and value at specified index
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.