C #6.0 (C # vNext): Numeric Literal Formats

Source: Internet
Author: User

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}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.