32
C # A Semitone Higher

History We first begin with Java which was released in 1995 by Sun Microsystems Initially Java was 100% interpreted at runtime and was very slow

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

C#

A Semitone Higher

Page 2: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

We first begin with Java which was released in 1995 by Sun Microsystems

Initially Java was 100% interpreted at runtime and was very slow

Eventually Just-in-Time compilers were created and used

The increased performance of Java and portability helped it grow in popularity

Page 3: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

The theory that Java applications could be developed on Windows and then easily be deployed on Unix platforms was clearly a threat to Microsoft

So Microsoft created their own Java Virtual Machine which was fairly reliable

However, their JVM introduced incompatible extensions which ruined portability

Page 4: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

So Sun sued Microsoft for violating the licensing terms

This hindered Microsoft’s JVM making it obsolete quickly as Sun updated their JVM

Clearly Microsoft and Java did not mix well

Page 5: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

In 1999 Anders Hejlsberg of Microsoft and his team began working on a new language initially called COOL (C-like Object Oriented Language)

The name was eventually changed to C# by the time it was announced, along with Microsoft’s .NET, in 2000

Page 6: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

James Gosling claimed that C# was an “imitation” of Java“[C# is] sort of Java with reliability,

productivity and security deleted.” Klaus Kreft and Angelika Langer

(authors)“Java and C# are almost identical

programming languages. Boring repetition that lacks innovation.”

Page 7: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

History

However, over time Java and C# have taken different paths

Page 8: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Overview Part of the .NET

Framework Compiler

creates intermediate code (CIL)

CLR creates machine code

Just-in-time compilation

Page 9: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

.exe or .dll

C# code can be compiled either to executable files or to library files (dynamically linked library)

csc program.cs compile to executable

csc /t:library lib.cs compile to dll

Page 10: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

C like language

For the most part, if you have programmed in Java, C, C++ or any other C like language, you will be used to most C# syntax

C# uses {..} block statements If else, while, do/while, for statements all

the same Even many keywords are the same

(especially compared to Java)

Page 11: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Object Oriented

At the heart it is object oriented

Supports inheritance and polymorphism

Classes are like objects with membersmethods, constructors, etc.

Page 12: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Basic Program

The Main methodstatic void Main() {…}static void Main(string[] args) {….}static int Main() {….}static int Main(string[] args) {…}

“Other overloaded versions of Main are permitted, however, provided they have more than one parameter, or their only parameter is other than type string[].” - Microsoft

Page 13: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Identifiers and Keywords

C# has 80 keywords Some are context sensitive keywords

They can be used as identifiers All keywords are usable as identifiers if

the @ symbol is in front of them@return, @null, @doubleint @int = 5; Console.WriteLine(@int);

Page 14: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Formatted Output

For output:Console.WriteLine(…..);

Format using {…} within a string{parameter #, spacing : special formatting}

Console.WriteLine(“{0,-10}.”, 100);> 100.

...WriteLine(“{1}, {0}”, firstName,lastName);>Rahimi, Shahram

Page 15: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Basic Programs

Page 16: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Basic Programs

Page 17: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Types

Value Typessbyte, short, int, long, byte (unsigned),

ushort, uint, ulong, char, float, double, decimal, bool

Enum, Struct, Nullable

Reference TypesObjects, string, class, interface, array,

delegate

Page 18: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Arrays

Arrays are treated the same as in Javaint[] n = new int[]{1,2,3,4};

SAME ASint[] n = {1,2,3,4};

SAME ASint[] n = new int[4];

n[0] = 1;

…..

Page 19: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Types

Nullable typeint? allows the int values to also be nullUseful for databases

DelegatesA data structure that refers to one or more

methodsSimilar to function pointers in C and C++

Page 20: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Delegates

Page 21: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Delegates

Page 22: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Switch

Switch statements are mostly the same EXECPT that they require an explicit branch statement like break or goto due to a static semantic rule

Also, switch statements in C# allow strings along with int and char

Page 23: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Switch

Page 24: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Unsafe Code

While C# has made strides to eliminate the need for pointers as data types with references and objects, it is still allowed

One must declare unsafe code to:Declare and operate on pointersPerform conversions between pointersTake addresses of variables

Page 25: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Unsafe Code Variables

Methods

Classes

Page 26: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Readability Pro

Basic syntax is C like (recognizable)Data must be explicitly typed and declaredVery common special words and statement

structure (loops and selection) Con

Not necessarily simple (delegates)Overloaded MainKeywords as identifiersAll statements end with }

Page 27: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Writability

ProMany ways to do one thing (like array

declaration)Delegates can simplify method callingInheritance

Con80 keywords to remember (and required

context)

Page 28: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Reliability

ProLimits use of pointers, programmer

becomes very aware of possible pointer issues.

Uses explicitly typed and declared variables

ConCan write code in unsafe mode Can be a complex language

Page 29: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

CostMemory references and automatic garbage

collection make creating quality code simpler and faster

Uses Microsoft Visual Studio as compiler ○ Free open source versions are available, but

premium versions can cost $2,000+Similar to well known languages but can be

a complex language

Page 30: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Who is using C#

It’s Microsoft Who isn’t using it?

Web design Gaming Medical Financial

Page 31: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Mono ProjectUNIX version of the Microsoft .NET

development platform

Open sourced based on C# .NET frameworkEnables Multi platform UNIX .NET

applications Implements various technologies developed

by Microsoft that have now been submitted to the ECMA for standardization.

Page 32: History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow

Sources “C# In Depth” – Jon Skeet Wikipedia

http://en.wikipedia.org/wiki/C_Sharp_(programming_language)

“C sharp Language Specification” – Microsoft

“Concepts of Programming Languages” -Sebesta

“Essential C# 4.0” – Michaelis http://www.mono-project.com/