- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are binary literals and digit separators in C# 7.0?
Binary Literals −
Before C# 7 we were able to assign only decimal and hexadecimal values to a variable.
In C# 7.0 binary literal has been introduced and it allows us binary value to the variable.
Digit Separator −
Digit Separator takes the form of a single underscore (_). This separator can be used within any numeric literal as a means of improving legibility.
Example Binary Literals −
Example
class Program{ public static void Main(){ var bn = 0b1000001; System.Console.WriteLine(bn.GetType()); System.Console.WriteLine(Convert.ToChar(bn)); Console.ReadLine(); } }
Output
System.Int32 A
Example Digit Seperator −
Example
class Program{ public static void Main(){ long Salary = 1_00_00_00_00_000; System.Console.WriteLine(Salary.GetType()); System.Console.WriteLine(Salary); Console.ReadLine(); } }
Output
System.Int64 100000000000
Advertisements