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
- Automation Using Selenium in C# With Example
- How to Execute C# Program on cmd (command-line)?
- How to Install and Setup Visual Studio for C#?
- What is .NET 3-Tier Architecture?
- Cross Join in LINQ
- Comparing two ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> in C#
- Compare two ValueTuple<T1, T2, T3, T4, T5, T6, T7> in C#
- Comparing two ValueTuple<T1, T2, T3, T4, T5, T6> in C#
- Comparing two ValueTuple<T1, T2, T3, T4, T5> in C#
- Comparing two ValueTuple<T1, T2, T3, T4> in C#
- Comparing two ValueTuple<T1, T2, T3> in C#
- Comparing two ValueTuple<T1, T2> in C#
- Comparing two ValueTuple<T1> in C#
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.