SlideServe
Menu
Préférences
© SlideServe · v2026

C# vs. C++

ruby-phelps avatar
9 diapositives · 300 Views · Oct 28, 2014

C# and C++ are both powerful programming languages, yet they have fundamental differences that affect their usage. C# is a modern, object-oriented, managed language designed for building applications on the .NET framework, whereas C++ is a versatile, high-performance language that provides more control over system resources. Key differences include inheritance rules, default constructors, array handling, and memory management. While C# uses delegates for type safety, C++ offers macros and preprocessor directives. This overview highlights the syntax variations and key features of each language, providing examples to illustrate their distinct functionalities. ###

C# vs. C++ - slide 1
01 / 9C# vs. C++
1 / 17

Télécharger la présentation

C# vs. C++
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. C# vs. C++ What's Different & What's New

  2. An example • C# publicsometypemyfn{ get; set; } • C++ public:  sometypemyfn { sometype get (); void set (sometype value); }

  3. Major differences • C# classes can only inherit from 1 base • C# structs do not allow • inheritance • explicit default constructors • C# arrays • are objects (can use x.length) • Use indexers& foreach • Declaration syntax is different int [ ] x;

  4. C# - 1 • No conversion to/from bool • Type long is 64 bits • Classes are passed by reference • Structs are passed by value (or use ref/out) • No fallthrough in switchstmts • New type: delegate is type-safe & secure • public delegate int x(p1, p2);

  5. Example of "delegate" // Declare the delegate -- defines the required fn signature:  delegate double MathAction(double num); class DelegateSample { // Regular method that matches signature: static double myDoubler (double input) { return input * 2; } static void Main() { // Instantiate delegate with a named method: MathActionma = myDoubler; Console.WriteLine (ma(4.5)); // Invoke the delegate  // Instantiate with an anonymous method: MathActionma2 = delegate(double input) { return input * input; }; Console.WriteLine(ma2(5)); } }

  6. C# - 2 • Must use "new" to hide inherited members • No preprocessor macros, use Globals instead • Formerly "#included" in C/C++ • Global.cs or a compiled into a Global library • References to those variables via Globals.VariableName • New keyword, finallyALWAYS executed even if errors occurred • More operators e.g.; isand typeof. • Different functionality for some logical operators.

  7. Logical operator differences in C# • & • ALWAYS evaluates both sides • Logical bitwise AND for int's • Logical AND for BOOL • | Similar to "&" except does logical OR • ^ Similar to "&" except does logical XOR • "is" compares types for compatibility if (x is myClass1) • "typeof" determines System.Type • E.g.; System.Type type = x.GetType();

  8. C# - 3 • "using" vs. typedefusing Project = PC.MyCompany.Project; • "extern" - used to declare a method that is implemented externally or to define an external assembly alias • "static" only usable for classes, fields, methods, properties, operators, events, and constructors

  9. Creating a "static" variable public class Request { private static int count=5; public static int Count { get { //Do not use the "this" keyword here //as "this" refers to "THIS INSTANCE" count++; // this really increments the count return Request.count; } // Do not provide a SET method } } In "main" call it this way: Console.WriteLine(Request.Count);