C # 6.0 (C # VNext) new features: Numeric Literal Formats

Source: Internet
Author: User

Numeric Literal Formats = Binary literals and separators
The individual is interpreted as "2-bit (2-digit) name and delimiter"

Previously available, mainly on decimal and 10-bit carry-over as follows:
var num1 = 1234; 10 decimal var num2 = 0x1234; 16 Rounding

2 name How do you pronounce it?
var num3 = 0b1010; 2 carry, the 10 digit represented is 10

And when we use the 2 to declare the name, that number will suddenly be very long, for example:
var NUM10 = 12345;var num2 = 0b11000000111001;

At this point, we can add the delimiter (Separator):
var num2 = 0b11_0000_0011_1001;

It's easier to see each number in this way.

The delimiter can be used in other numeric types name as follows:
var num5 = 1_234_567_890; 10 rounding: expressed as 123456789var num6 = 0XFF_FA_88_BC; 16 Rounding: Replace with 10 for 4294609084var num7 = 0b10_01__01_10; 2 rounding: 10 for 150

Finally, let's look at an 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}


C # 6.0 (C # VNext) new features: Numeric Literal Formats

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.