10/24/2011

Key differences between C# and C++


It was a surprise that there was no thread for C++ recipes. Though C++ and C# are quite similar there are some very key and major differences.
-I find C# resembles the style of java more than that of C++ i many ways.
(I will be following this up with some coding recipes, to hopefully start a C++ reciped thread)

Method/Function Declarations:
C++:
public:
Constructor() { }
void aMemberFunction() { }
void aFunctionDeclaration();
private:
void someOtherFunction() { }
int aVariable;
C#:
private aVariable;
public void aMemberFunction() { }
public void aFunctionDeclaration();
private void someOtherFunction() { }

Class Declaration:
For those who know what a managed class is:
C++:
__gc class A_Class{ };
*NOTE that C++ classes end with a ;
C#:
automatically done so:
class A_Class{ }

Inheritence:
C++:
will allow multiple inheritence. eg. allows a method to be overriden many times in subclasses (derived classes).
C#:
supports inheritence, but not multiple, only 1 override per method/function/

Includes:
C++:
allows header files and other class files to be included using the #include keyword.
C#:
does not have such a quality, but the using directive allows other types to be referenced from another class (namespace as it is formerly called) without declaring it’s context.

Switch: *Props to PCurd for pointing out my careless mistake :)
C++:
supports the switch statement, and fall through.
C#:
does not support fall through in the switch statement, and i have not come across any replacement.
*These are the largest of the differences

0 komentar:

Posting Komentar