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