c++| Difference | grammar
The following table contains important comparisons between C + + and C # features. If you are a C + + programmer, this table will provide you with the most important differences between the two languages.
Note C + + and C # projects are derived from different project models. For information about the differences between C + + and C # projects, see Item Management and using Solution Explorer in the project.
Functional reference topics
Inheritance: A class can only inherit an implementation from a base class. In addition, a class or interface can implement multiple interfaces.
Arrays: declaring C # arrays and declaring C + + arrays differ in syntax. In C #, the [] tag appears after the array type.
BOOL Type: There is no conversion between bool type and other types (especially int).
Long: In C #, a Long data type is 64 bits and 32 bits in C + +.
struct type: In C #, classes and structs are semantically different. struct is a value type, and class is a reference type.
Switch statement: Unlike switch statements in C + +, C # does not support running from one case label to another.
Delegate type: Delegates are basically similar to function pointers in C + +, but the former is type-safe and safe.
Overrides a base class member from a derived class call.
Use the new modifier modifier explicitly to hide an inherited member.
The declaration rewrite method requires a override keyword.
Preprocessor directives are used for conditional compilation. Header files are not used in C #.
Exception handling: Using the finally statement.
C # operators: C # supports other operators, such as IS and TypeOf. It also introduces the different functions of some logical operators.
Use of the keyword extern.
Use of the keyword static.
The method that replaces the C + + initialization list on the constructed base class.
The general structure of a C # program: namespaces, classes, structs, delegates, and enumerations.
The main method and the main function in C + + are declared differently.
Method parameters: C # supports ref and out parameters, which supersede pointers passing arguments by reference.
Use pointers only in unsafe mode in C #. Unsafe
Overloaded operators are executed in C # in different ways.
String: C # string is different from C + + string. String
The foreach keyword allows you to iterate through arrays and collections. foreach, in
There are no global methods and global variables in C #: Methods and variables must be contained in type declarations, such as class or struct.
There are no header files and #include directives in C #: The using directive is used to reference types in namespaces in other incompletely qualified type names.
Local variables in C # cannot be used before initialization.
destructor: In C #, the call time of the destructor cannot be controlled because the destructor is invoked automatically by the garbage collector.
Constructors: Similar to C + +, if a class constructor is not provided in C #, the default constructor is automatically generated for you. The default constructor initializes all fields to their default values.
C # does not support bit fields. C + + bit fields
C # 's input/output services and formatting depend on the Run-time library of the. NET Framework.
In C #, method parameters cannot have default values. If you want to get the same effect, use the method overload.