Exforsys
+ Reply to Thread
Results 1 to 2 of 2

C# compared to C & C++

This is a discussion on C# compared to C & C++ within the C Sharp forums, part of the Programming Talk category; Compared to C and C++, the language is restricted or enhanced in a number of ways, here's some of them ...

  1. #1
    klorpet is offline Member Array
    Join Date
    May 2006
    Answers
    39

    C# compared to C & C++

    Compared to C and C++, the language is restricted or enhanced in a number of ways, here's some of them (feel free to add to this list):
    • True support for pointers. However pointers can only be used within unsafe scopes, and only programs with appropriate permissions can execute code marked as unsafe. Most object access is done through safe references, which cannot be made invalid, and most arithmetic is checked for overflow. An unsafe pointer can be made to not only value-types, but to subclasses of System.Object as well. Also safe code can be written that uses a pointer (System.IntPtr).
    • Managed memory cannot be explicitly freed, but instead is garbage collected when no more references to the memory exist. (Objects that reference unmanaged resources, such as an HBRUSH, can be instructed to release those resources through the standard IDisposable interface, which provides a pattern for deterministic deallocation of resources.)
    • Multiple inheritance is prohibited (although a class can implement any number of interfaces). This was a design decision by the language's lead architect (Anders Hejlsberg) to avoid complication, avoid 'dependency hell,' and simplify architectural requirements throughout CLI (Common Language Infrastructure).
    • C# is more typesafe than C++. The only implicit conversions by default are safe conversions, such as widening of integers and conversion from a derived type to a base type (and this is enforced at compile-time and, indirectly, during JIT). There are no implicit conversions between booleans and integers and between enumeration members and integers, and any user-defined implicit conversion must be explicitly marked as such, unlike C++'s copy constructors.
    • Syntax for array declaration is different ("int[] a = new int[5];" instead of "int a[5];").
    • Enumeration members are placed in their own namespace.
    • C# 1.0 lacks templates, however, C# 2.0 provides generics.
    • Properties are available which results in syntax that resembles C++ member field access, similar to VB.
    • Full type reflection and discovery is available.



  2. #2
    Angela is offline Member Array
    Join Date
    Apr 2006
    Answers
    85
    Good post. C# is derived from C++ and Java. The main programming codes are like C++ and also has the style of Java programming. So it is easier to program in C# than in C++.


Latest Article

Network Security Risk Assessment and Measurement

Read More...