C #6.0 (C # vNext): Numeric Literal Formats
Numeric Literal Formats = Binary literals and separators
I personally interpret it as "2-digit (2-digit) Real-word and separator 」
Previously available, mainly decimal places and decimal places are as follows:
Var num1 = 1234; // 10 carry var num2 = 0x1234; // 16 carry
How to declare 2 carry real words?
Var num3 = 0b1010; // 2 carry, representing 10 carry numbers
When we use 2-digit to declare a real word, the number will suddenly be very long, for example:
var num10 = 12345;var num2 = 0b11000000111001;
In this case, we can add the Separator (Separator ):
var num2 = 0b11_0000_0011_1001;
This makes it easy to see each number.
Separators can be used in other numeric types as follows:
Var num5 = bytes; // 10 carry: represents 123456789var num6 = 0xFF_FA_88_BC; // 16 carry: replace it with 10 carry: 4294609084var num7 = 0b10_01 _ 01_10; // 2 carry: replace 10 with 150
Let's look at another example:
[Serializable][Flags][System.Runtime.InteropServices.ComVisible(true)]public enum FileAttributes{ ReadOnly = 0b00_00_00_00_00_00_01, // 0x0001 Hidden = 0b00_00_00_00_00_00_10, // 0x0002 System = 0b00_00_00_00_00_01_00, // 0x0004 Directory = 0b00_00_00_00_00_10_00, // 0x0010 Archive = 0b00_00_00_00_01_00_00, // 0x0020 Device = 0b00_00_00_00_10_00_00, // 0x0040 Normal = 0b00_00_00_01_00_00_00, // 0x0080 Temporary = 0b00_00_00_10_00_00_00, // 0x0100 SparseFile = 0b00_00_01_00_00_00_00, // 0x0200 ReparsePoint = 0b00_00_10_00_00_00_00, // 0x0400 Compressed = 0b00_01_00_00_00_00_00, // 0x0800 Offline = 0b00_10_00_00_00_00_00, // 0x1000 NotContentIndexed = 0b01_00_00_00_00_00_00, // 0x2000 Encrypted = 0b10_00_00_00_00_00_00 // 0x4000}