What are the differences between C++ and C#?

C# was developed as an independent language by Microsoft. However, it borrowed heavily from C and C++ programming languages. While C is a procedure oriented programming language, C++ is an object oriented programming language, whereas C# is a multi-paradigm programming language as it has concepts of both procedure oriented programming and object-oriented programming.

C++

C#

Developed from C

Developed from C and C++

Low level and platform neutral programming language

High level language that is component oriented

When compiled, C++ code is converted directly into assembly language code

When compiled, C# code is converted into Intermediate language code and then converted into executable code through Just-In-Time compilation

Allocated memory has to be manually deleted

Memory management automatically handled by garbage collector

In Switch Statement, the test variable cannot be a string.

In Switch Statement, the test variable can be a string.

When break statement is not given, the fall through will happen to the next case statement even if the current case statement has any code.

When break statement is not given, the fall through will not happen to the next case statement if the current case statement has any code

Does not contain ‘for each’ statement

Contains ‘for each’ statement

Structs behave like classes

Structs can contain only value types

The default access to Structs is public

Structs is sealed and cannot have a default no-argument constructor

Delegates, events and properties cannot be specified as class members.

Delegates, events and properties can be specified as class members.

The end of the class definition has a closing brace followed by a semicolon

The end of the class definition has just a closing brace

The access modifiers are public, private, protected. It does not have internal and protected internal access modifiers

The access modifiers are public, private, protected, internal and protected internal

Does not have finally block in exception handling mechanism.

Has finally block in exception handling mechanism.

The exception can throw any class.

The exception can only throw a class that is derived from the System.

Has the concept of function pointers

Does not have the concept of function pointers

Has a concept called Delegates

Does not have the concept of Delegates

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.