Exforsys
+ Reply to Thread
Results 1 to 5 of 5

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
    41

    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++.


  3. #3
    klorpet is offline Member Array
    Join Date
    May 2006
    Answers
    41
    Thanks Angela


  4. #4
    nguyenanhduc is offline Junior Member Array
    Join Date
    Jun 2006
    Answers
    1

    Post how to write website for mobile phone

    Help me !
    I want to write the website for mobile but i don't know "How to write ?" Can you help me ?


  5. #5
    klorpet is offline Member Array
    Join Date
    May 2006
    Answers
    41
    You should post this in the project request area so that more people see it and can offer assistance. You might want to include timeline and any other details.

    Good luck.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...