C++ vs C#

Discussion in 'NDS - Emulation and Homebrew' started by Malamear, Aug 28, 2009.

Aug 28, 2009

C++ vs C# by Malamear at 8:26 PM (782 Views / 0 Likes) 3 replies

  1. Malamear
    OP

    Newcomer Malamear Newbie

    Joined:
    Nov 27, 2008
    Messages:
    8
    Country:
    United States
    What's the difference?
     
  2. Malamear
    OP

    Newcomer Malamear Newbie

    Joined:
    Nov 27, 2008
    Messages:
    8
    Country:
    United States
    Also the Pros and Cons?
     
  3. Flame

    Member Flame Me > You

    Joined:
    Jul 15, 2008
    Messages:
    3,411
    Country:
    Pro C#:

    * garbage collection
    * array bounds checking
    * huge .NET-Framework library
    * types have a defined size (e.g. a long is 64Bit)
    * strings are encoded in UTF/16
    * autoboxing - every type can be treated as if it inherits from object
    * supports constructor-chaining (one constructor can call another constructor from the same class)
    * when a virtual method is called in a constructor, the method in the most derived class is used
    * static constructors (run before the first instance of the class is created)
    * exceptions have access to a stack trace
    * advanced runtime type information and reflection
    * supports variadic functions nicely
    * built-in support for threads
    * no need for header files and #includes
    * no fall-through on switch-statements
    * arithmetic operations can be checked for overflow if required
    * objects must have a definite value before being used
    * attributes can be attached to classes and retrieved at runtime
    * no forward declarations required, classes can be arranged at will
    * access to class members / functions is done only by the dot (no more -> or :[​IMG]
    * conditional functions (e.g. for debugging)
    * structs and classes are actually different (structs are value types, have no default constructor in general cannot be derived from)
    * supports properties
    * readonly members are const, but can be changed in the constructor
    * finally block for exceptions
    * arrays are objects
    * support for anonymous functions
    * supports the base keyword for calling the overridden base class

    Pro C++

    * better performance
    * portability
    * multiple inheritance
    * deterministic destruction (allows RAII)
    * any type can be thrown as exception (only classes derived from System.Exception in C#)
    * ability to enforce const-correctness
    * implicit interfaces on generics (in C#, generics must be constrained with an interface)
    * offers pointers (C# only offers pointers in unsafe mode)
    * support for macros
    * support for global variables, functions, constants
    * allows default arguments on function parameters
    * STL
    * supports bitfields

    Where C# is just different from C++

    * value types and reference types exist (struct is value-type, class is reference-type)
    * value types live on the stack, reference types on the heap
    * references can point to null (must not be valid)
    * code is packaged in assemblies in C#
    * no automatic conversion from int to bool in C#
    * main-function is called Main in C#
    * no semicolon after a class declaration in C#
    * everything derives from object or can be treated as if


    http://www.thinkingparallel.com/2007/03/06...-point-of-view/


    google [​IMG]

    one big con of C# is that it needs .net framework, windows only. i think they is some apps on the linux which can make c# run on linux.

    But C# wouldnt work on DS.
     
  4. sadak5

    Member sadak5 GBAtemp Fan

    Joined:
    Feb 27, 2007
    Messages:
    421
    Location:
    Mexico City
    Country:
    Mexico
    there is a port of the .NET Framework for Linux called MONO. Also, the latests features like Silverlight (programable in all .NET languages) have runtime for mac, windows y linux.
     

Share This Page