C # (16-19)

Source: Internet
Author: User

16. switch statement

Switch statements in C # can use integer, character, enumeration, or (unlike C ++ or Java) strings. In Java and C ++, if you ignore a break statement in any case statement, other case statements may be executed. I cannot figure out why this rarely-needed and error-prone behavior has become the default behavior in Java and C ++, and I am very happy to see that C # is not like this.

Because C # does not support passing through one case label to another. If needed, you can use goto case or goto default]

17. predefined types

C # The basic types are basically the same as those of Java. In addition to the former, the unsigned types are added. C # contains sbyte, byte, short, ushort, int, uint, long, ulong, char, float, and double. The only surprising thing is that there is a 16-byte floating-point numeric type decimal, which is written in 12 bytes by mistake, which can take full advantage of the latest processor.

Although decimal occupies 128 bits, its value range is much smaller than float (32 bits) and Double (64 bits, however, its accuracy is much higher than that of the latter two, which can meet the financial computing requirements with extremely high accuracy]

18. Field Modifier

The field modifiers in C # are basically the same in Java. To indicate fields that cannot be modified, C # uses the const and readonly modifiers. The const field modifier is like the final field modifier of Java. The actual value of this field is compiled as part of the IL code. Read-Only fields are calculated at run time. For the standard C # library, this can be upgraded without disrupting your deployed code.

19. Jump statement

There is nothing more surprising here, except for the notorious goto statement. However, this is not the same as the basic goto statement we remembered 20 years ago. A goto statement must point to a tag. The annotation goto statement must be in the scope of the tag. In other words, it only allows the use of a goto statement to pass control to a nested scope, instead, you cannot pass the control to a nested domain. You can also select a goto case statement in the switch statement ]. The usage of pointing to a tag is similar to that of continue. Java labels have a higher degree of freedom ]. In C #, A goto statement can point to any part of its scope. This scope refers to the same method or finally program block, the destination of the goto statement must also be in the same finally statement block ]. The continue statement in C # is basically equivalent to that in Java, but C # cannot point to a label.

Java uses goto as a reserved word, but does not implement it]

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.