What are the binary literal and number separators in C# 7.0?

WBOY
Release: 2023-09-08 12:53:02
forward
1180 people have browsed it

C# 7.0 中的二进制文字和数字分隔符是什么?

Binary literals -

Before C# 7, we could only assign decimal and hexadecimal values ​​to a variable.

Introduced in C# 7.0, binary literals allow us to pass binary values ​​to variable.

Number separator -

The number separator takes the form of a single underscore (_). This separator can be used Can be used in any digital text as a way to improve legibility.

Binary Literal Example -

Example

class Program{
   public static void Main(){
      var bn = 0b1000001;
      System.Console.WriteLine(bn.GetType());
      System.Console.WriteLine(Convert.ToChar(bn));
      Console.ReadLine();
   }
}
Copy after login

Output

System.Int32
A
Copy after login

Number Separator Example -

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();
   }
}
Copy after login

Output

System.Int64
100000000000
Copy after login

The above is the detailed content of What are the binary literal and number separators in C# 7.0?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template