Introduction to C# 3.0

Post on 10-May-2015

534 views 1 download

Tags:

description

C#

Transcript of Introduction to C# 3.0

Overview of C# 3.0

Presentation created by Eriawan Kusumawardhono, for RX Communica

C# 3.0 is?

A part of .NET programming languages from Microsoft

It is released with Visual Studio 2008 and .NET 3.5

Historical perspective of C# 3.0A quick tour of historical view

Beginning of C#

C# was a first managed language to compete with Java

Microsoft was lost in court because of J++ implementation

C# 1.0 was designed and developed in 1999

C# 1.0 has basic OOP of inheritance, polymorphism

Property mechanism is the same concept as VB 4.0+

C# is?

Statically typed language Early bound Based on CLR and CTS of .NET Also part of “curly braces” languages

such as C, C++, Objective C, Java Imperative language as part of OOP

Managed language is simply virtualization

Just like Java runs in its VM Virtualization promotes cleaner

environment, optimization, garbage collection, thread optimization within one “virtual” platform

A light lose coupling between OS and application written in managed environment or virtualization

Reduced OS version dependency and functionality

So why?

It is simply, raising an abstraction, not adding abstraction

Focusing more on what you want to be done, not how

The sample of adding abstraction: batch command

DOS batch command

Console API

USER32 API

Raising level of abstraction

Assembly

Procedural

OOP

Managed environment

Conceptual difference of abstraction

RAISING ABSTRACTION

Intended to be more declarative

Does not hide the detail of underlying platform

Still can access the OS API using P/Invoke in .NET and JNI in Java

ADDING ABSTRACTION

Not intended to be more declarative

Often creating more new conceptual topics

Often hide the detail of the underlying platform

What comes with C# 2.0

Adding generics on type and method declaration

Generic type inference on methods and method parameters

Reflection granularity Nullable types Iterator of “yield” Anonymous delegate

Current release of C#: 3.0Present state of C# (2009)

Continuous design from previous releases

New features are based on previous releases

Maintaining runtime compatibility and based on CLR of .NET 2.0

C# 3.0 theme

LINQ Functional programming in style

LINQ is build on

Query comprehension Extension method Lambda expression Expression tree Property initializer Anonymous type initializer Local variable type inference

Quick feature look

var x = from c in db.customer where c.City ==“London” select c.Name, c.City

var x = db.Customer .Where(c => c.City == “London”) .Select(c=> new {c.Name,c.City}

Query comprehension

Local type infer

Extension method

Lambda expression

Anonymous object/type initializer

Query comprehension

Adapting SQL query of SELECT Not a real keyword in C#, it is a

pseudo keyword SELECT, WHERE, ORDER BY, GROUP

BY is then translated into calls to extension methods

Lambda Expression overview

It is simply an anonymous delegate but with the functional math syntax

Taken from ideas in Lambda calculus

Extension methods

Adding static method to a class or interfaces without deriving it

Use it wisely Can be a bad smell in coding

practice

Next is: C# 4.0Main theme: support for dynamic type

Overview of C# 4.0

Dynamic type Co and Contra variance Optional and named parameters No PIA

Beyond C# 4.0

Compiler as a service True meta programming Method execution into multi core

(parallel) Function purity

End