The following table contains important comparisons between C++ and C# features. If you are a C++ programmer, this table will give you the most important differences between the two languages at a glance. For details, use the link to browse to the detailed C# document.
Feature | Refer to the topic |
---|---|
Inheritance: A class can inherit implementation from one base class only. Also a class or an interface can implement multiple interfaces. | class |
Arrays: The syntax of declaring C# arrays is different from that of C++ arrays. The tokens "[]" appear following the array type in C#. | Arrays |
The bool type: There is no conversion between the bool type and other types (specifically int). | bool |
The struct type: In C#, classes and structs are semantically different. A struct is a value type, while a class is a reference type. | struct |
The switch statement: Unlike the C++ switch statement, C# does not support fall through from one case label to another. | switch |
The delegate type: Delegates are roughly similar to function pointers in C++, but they are type-safe and secure. | delegate |
Calling the overridden base class members from derived classes. | base
See also the examples for override |
Using the new modifier to explicitly hide an inherited member. | new |
Declaring override methods requires the override keyword. | override |
Preprocessor directives are used for conditional compilation. No header files are used in C#. | Preprocessor Directives |
Exception handling: Using the finally statement. | try-finally |
C# operators: C# supports additional operators such as is and typeof. It also introduced different functionality of some logical operators. | & Operator |
Use of the extern keyword. | extern |
Use of the static keyword. | static |
An alternative way to the C++ initialization list in constructing the base class. | See the examples for virtual |
The general structure of the C# program: namespaces, classes, structs, delegates, and enumerations. | General structure of a C# program |
The Main method is declared differently from the main function in C++. Also, compare the usage of the command-line arguments for each language. | Main |
Method parameters: C# supports ref and out parameters, which are used instead of pointers in passing parameters by reference. | ref |
Pointers are allowed in C# but only in unsafe mode. | unsafe |
Overloading operators is performed differently in C#. | C# Operators |
Strings: C# strings are different from C++ strings. | string |
For complete comparisons between C# and other programming languages, see the Language Equivalents documentation.