Good Resources

C# FAQ for C++ programmers

Some Key Differences

Classes and structs

Classes and structs are almost the same in C++ – this is not true for C#.  In C#, structs are value types (instances stored directly on the stack, or inline within heap-based objects), whereas classes are reference types (instances stored on the heap, accessed indirectly via a reference). Also structs cannot inherit from structs or classes, though they can implement interfaces. Structs cannot have destructors. A C# struct is much more like a C struct than a C++ struct.

Memory types

Chars and strings in .NET are 16-bit (Unicode/UTF-16), not 8-bit like C++

#include

There is no '#include' statement – use "using" instead.  See here.

#define

There is no '#define' statement – use const instead.  See here.

Header Files (*.h)

Nope, not used in C#.  See here.

Using C++ code with C#

Where existing C++ code must be used with a new application, the existing code can be wrapped using C++/CLI to allow it to interop with C#.

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *