Home>Article>Backend Development> What are the binary literal and number separators in C# 7.0?

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

WBOY
WBOY forward
2023-09-08 12:53:02 1070browse

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

Output

System.Int32 A

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

Output

System.Int64 100000000000

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete