C # basic syntax differences between C # And C ++ Data Types

Source: Internet
Author: User

C # basic syntax differences between c # And c ++ Data Types
Basic Data Type:

In c #, sbyte indicates-128 ~ An integer between 127, which is the same as the char of the c ++ crowd; byte in c # indicates 0 ~ An integer between 255, represented by unsigned char in c ++; in c #, char represents a unicode character, which is stored as 0 ~ The integer between 65535 and c ++.

Short indicates 16-bit unsigned, which is the same as c ++; ushort indicates a 16-bit unsigned integer; similarly, int uint, long, ulong, this is similar to c ++ (in c ++, there are no uint and ulong, which are unsigned int and unsigned long respectively ). In c #, each type of data also corresponds to the standard type in the. net Framework. It can also be seen that c # is an alias of the. net basic data type.

The string type in c # is similar to that in c ++ stl standard library. In c #, strings are reference types, while other types are value types.

Variable naming rules:

The variable naming rules in c # are basically the same as those in c ++. In c #, the first character of the variable name must be a letter, underscore, or @. The subsequent letter can be a letter, number, or underscore, and cannot contain hyphens (-), periods.

C # escape sequence: c # not only supports the use of basic escape characters such as "n" in c ++, but also supports the use of @ to operate the entire string, as follows: Use @, no need to add

"C: windowsxp"-> @ "c: windowsxp"

OPERATOR:

The operators in c # are basically the same as those in c ++. For example, they also support frontend and backend ++, --; + =,-=, * =,/=, and % =, the operator priority is also consistent.

Namespace domain:

A namespace domain is a good thing. It can encapsulate code into different namespaces to avoid name conflicts. In c ++, this is not necessary and is often ignored in many applications. However, in c #, it is basically necessary, this shows the difference between the vc and c # instances provided by ms.

In c ++, access to a namespace domain uses the domain operator ':', for example, std: vector <int>. in c #, use '. ', such as system. text (the system namespace is.. net application ).

Declare the namespace in c # And use using **, such as using system;

In c ++, declare the namespace and use using namespace **, such as using namespace std

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.