C# vs. C++ What's Different & What's New. An example C# public sometype myfn { get; set; } C++ public: sometype myfn { sometype get (); void set (sometype.

Slides:



Advertisements
Similar presentations
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Advertisements

Introduction to the C# Programming Language for the VB Programmer.
Structure of a C program
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Java Syntax Primitive data types Operators Control statements.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Arrays and Objects OO basics. Topics Basic array syntax/use OO Vocabulary review Simple OO example Instance and Static methods Static vs. instance vs.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
C#C# Classes & Methods CS3260 Dennis A. Fairclough Version 1.1 Classes & Methods CS3260 Dennis A. Fairclough Version 1.1.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Introduction to Building Windows 8.1 & Windows Phone Applications.
ILM Proprietary and Confidential -
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Advanced C# Types Tom Roeder CS fa. From last time out parameters difference is that the callee is required to assign it before returning not the.
OOP in C++ CS 124. Program Structure C++ Program: collection of files Source (.cpp) files be compiled separately to be linked into an executable Files.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Methods Methods are how we implement actions – actions that objects can do, or actions that can be done to objects. In Alice, we have methods such as move,
Lecture 8: Object Oriented Programming. What is a Programming Object? An object is an instance of a class. A class is a template for an object. Everything's.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Introduction to Object-Oriented Programming Lesson 2.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Chapter 7 Constructors and Other Tools Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Unit 2. Constructors It initializes an object when it is created. It has same as its class and syntactically similar to a method. Constructor have no.
C# for C++ Programmers 1.
Classes C++ representation of an object
Data types Data types Basic types
Inheritance and Polymorphism
Java Primer 1: Types, Classes and Operators
Methods Attributes Method Modifiers ‘static’
C Basics.
Structs.
Pass by Reference, const, readonly, struct
Java Programming Language
Conditional Statements
Interfaces.
Module 2 Variables, Assignment, and Data Types
Chapter 14 Abstract Classes and Interfaces
CIS 199 Final Review.
Java Programming Language
Classes C++ representation of an object
Creating and Using Classes
Presentation transcript:

C# vs. C++ What's Different & What's New

An example C# public sometype myfn { get; set; } C++ public: sometype myfn { sometype get (); void set (sometype value); }

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;

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 fall-through in switch stmts New type: delegate is type-safe & secure – public delegate int x(p1, p2);

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: MathAction ma = myDoubler; Console.WriteLine (ma(4.5)); // Invoke the delegate // Instantiate with an anonymous method: MathAction ma2 = delegate(double input) { return input * input; }; Console.WriteLine(ma2(5)); }

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, finally ALWAYS executed even if errors occurred More operators e.g.; is and typeof. Different functionality for some logical operators.

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();

C# - 3 "using" vs. typedef using 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

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);

Strings Use the symbol for verbatim strings E.g.; these are "C:\\myfile.txt" The sign avoids the need for escape characters for special symbols like the "\" Allows for newlines, spaces & tabs in literals Literals can span multiple lines