C++ | C# |
Reference to a class in another file of a project requires an include file | No include file needed |
Reference to a class in an external DLL requires an include file and the DLL’s .LIB file passed to the linker | No .LIB file needed. Add a reference to the DLL in the build(example: csc /r:external.dll helloworld.cs) |
Exported symbols must use declspec or .DEF file | No declspec or .DEF file. Public symbols are exported, private/protected are not. ”internal” symbols are only available within module. |
Referencing a class/structure before it is declared requires forward declaration | Forward declaration not needed. Declaration order is insignificant. |
Switching to Unicode/16-bit text requires: - Different entry point (main/wmain)
- Prefixing text with “L” or “_T”
- New string manipulation functions
| Unicode is the native string format |
NULL is a concept, not part of the language. It is typically defined as 0 and thus is the equivalent of 0. | null is a keyword. It is not equivalent to 0. |
Basic data types (int, float, char, etc.) cannot accept a “null” value. Only pointers can have a “null” value. | All C# types can accept null as a value - For type T with null support, use type T?
- For example, int with null support is int?
|
No support for “foreach” | foreach keyword for iterating over a collection |
Support for try and catch. No support for "finally” | try-catch-finally support. finally is always called, regardless of exception or not |
No notification of overflow operations. For example: unsigned x = UINT_MAX; x++; // x == 0 now, no exception thrown | Using checked/unchecked you can get overflow or exception thrown behavior |
No native support for critical sections | lock keyword for critical sections |
For switch statements, break is optional. | break is required (to prevent bugs from accidentally forgetting to add break) |
No built-in documentation | XML documentation via “///”- prefixed comment. Used by IntelliSense in Visual Studio |
Cannot split the definition of a class across multiple files | Partial classes allow breaking up a source file (useful when multiple people are working on a class or when part of a class is auto-generated) |
No support for mixing versions of libraries | Can mix library versions without breaking existing code. |
Developer must manage deletion of memory and potential issues from reading/writing to invalid memory | Garbage collection: - No memory leaks
- Can’t read uninitialized variables
- Can’t index past array boundaries
|
Types do not share a common root | All types derived from base “object” |