NET and C#

Preview:

DESCRIPTION

.NET and C#. Peter Groenewegen Vrije Universiteit pgroene@few.vu.nl. . NET and C#. .NET. Part 1. Partner Apps. Partner Services. MS Apps. MS Services. User Interface. User Experience. Compound Document. Universal Canvas. File System. XML Store. APIs. Building Blocks. - PowerPoint PPT Presentation

Citation preview

1

.NET and C#.NET and C#

Peter Groenewegen

Vrije Universiteitpgroene@few.vu.nl

2

..NET and C#NET and C#

Part 1Part 1

.NET.NET

3

The .NET EvolutionThe .NET Evolution

User ExperienceUser Experience

XML StoreXML Store

Building BlocksBuilding Blocks

PC and other devicesPC and other devices

Universal CanvasUniversal Canvas

.NET Platform.NET Platform

MS MS ServicesServices

Partner Partner ServicesServices

APIsAPIs

User InterfaceUser Interface

File SystemFile System

PCPC

Compound DocumentCompound Document

Windows PlatformWindows Platform

MS MS AppsApps

Partner Partner AppsApps

As big a transition as from As big a transition as from DOS to WindowsDOS to Windows

4

.NET.NET

Simpler programming

model

WebServices

Many devices

5

Many DevicesMany Devices

Intel Win32

Winformsuniversal runtime

6

Intermediate LanguageIntermediate Language

All languages are compiled to an All languages are compiled to an intermediate languageintermediate language

7

Intermediate LanguageIntermediate Language

Computer Language

Intel PPC 6502runtime

librariesruntime

librariesruntime

libraries

8

Intermediate LanguageIntermediate Language

Computer Language

Intel PPC 6502

Intermediate Language runtime

libraries

9

Intermediate LanguageIntermediate Language

C#

Intel PPC 6502

MSIL runtime

libraries

Perl Pascal

runtimelibraries

runtimelibraries

runtimelibraries

10

Common Language RuntimeCommon Language Runtime

11

.NET.NET

Simpler programming

model

WebServices

Many devices

12

Web ServicesWeb Services

DCOM ASP

ASP+, Webforms

SOAP

Biztalk

13

Web ServicesWeb Services

<html>…</html>

???????

ASP

14

Web ServicesWeb Services

Webservice

Webservice

Webservice

Webservice

15

Web ServicesWeb Services

DCOM

DCOM

DCOM

CORBA

CORBA

CORBA

CORBA

CORBACORBA

implementations are not

compatible

DCOM location transparency does not hold

on the web

CORBA and DCOM are not

compatible

16

Web ServicesWeb Services

Functionality for development and management of .NET services:Functionality for development and management of .NET services: Application Center 2000: Extreme reliability and scalabilityApplication Center 2000: Extreme reliability and scalability Internet Security & Acceleration Server: Firewall and proxy Internet Security & Acceleration Server: Firewall and proxy

serverserver Commerce Server: analyzing site usage Commerce Server: analyzing site usage BizTalk Server 2000: Business process orchestration & BizTalk Server 2000: Business process orchestration &

Business-to-business document interchange using XML Business-to-business document interchange using XML SQL Server 2000: Easy-to-use database systems with native SQL Server 2000: Easy-to-use database systems with native

Extensible Markup Language (XML) support Extensible Markup Language (XML) support Host Integration Server 2000: Integration with host systems Host Integration Server 2000: Integration with host systems

and their dataand their data Mobile Information 2001 Server: Integration with mobile Mobile Information 2001 Server: Integration with mobile

devices devices

17

.NET.NET

Simpler programming

model

WebServices

Many devices

18

Simpler programming modelSimpler programming model

ComponentBased Java

C#

Object Oriented

C++

Python Perl

Cobol

Haskell

VB

19

Simpler programming modelSimpler programming model

Cross-language implementation inheritance Cross-language exception handling Cross-language debugging ASP+ pages in any language Client-side scripts in any language

Languages include Perl, Python, COBOL, Pascal, Oberon, ...

Haskell, Mercury, Eiffel, …

C, C++,C#, …

20

VersioningVersioning

X.dllVersion 1949

Implementation relied on “secret” API

removed in new version

X.dllVersion 2001

Office 2000SP1

Leisure suit Larry

Salary

The programmer was aware of a bug

and thought he was smart to use

the feature

21

What else...What else...

Free standardsFree standards XMLXML PerformancePerformance Backwards compatibilityBackwards compatibility Lots of code ready to useLots of code ready to use ......

22

The .NET evolutionThe .NET evolution

User ExperienceUser Experience

XML StoreXML Store

Building BlocksBuilding Blocks

PC and other devicesPC and other devices

Universal CanvasUniversal Canvas

.NET Platform.NET Platform

MS MS ServicesServices

Partner Partner ServicesServices

APIsAPIs

User InterfaceUser Interface

File SystemFile System

PCPC

Compound DocumentCompound Document

Windows PlatformWindows Platform

MS MS AppsApps

Partner Partner AppsApps

DOS DOS Windows = Windows = Windows Windows .NET .NET

23

.NET and C#.NET and C#

Part 2Part 2

C#C#

24

C#C#

Not MS alternative for Java

Language for programming.NET framework

Which is MS alternative forJVM

25

Hello WorldHello World

using System;class Hello{ static void Main() { Console.WriteLine("Hello world"); }}

csc HelloWorld.cs

ildasm HelloWorld.exe

DEMO

26

NamespacesNamespaces TypesTypes, namespaces, namespaces

Type declarationsType declarations Classes, interfaces, structs, enums, Classes, interfaces, structs, enums,

delegatesdelegates

MembersMembers Fields,methods, constants, Fields,methods, constants, propertiesproperties, ,

events, events, indexersindexers, operators, , operators, constructors, destructorsconstructors, destructors

package

inner classes

Java Beansvoid finalize

()

C# Program StructureC# Program Structure

27

Boxing/UnboxingBoxing/Unboxing

BoxingBoxing Allocates box, copies value into itAllocates box, copies value into it

UnboxingUnboxing Checks type of box, copies value outChecks type of box, copies value out

int i = 123;object o = i;int j = (int)o;

123i

o

123

System.Int32

123j

28

Value TypesValue Types

Struct type struct Point { int x, y; }

Simple typeSimple type int i;

Enums typeEnums type enum State { Off, On }

Everything is really an object

29

Refrence typesRefrence types

Interface typeInterface type Delegate typeDelegate type Class typeClass type Array typeArray type

30

Unsafe codeUnsafe code

Unsafe codeUnsafe code Low-level code without leaving the boxLow-level code without leaving the box Enables unsafe casts, pointer arithmeticEnables unsafe casts, pointer arithmetic

Declarative pinningDeclarative pinning fixed statementfixed statement

Basically “inline C”Basically “inline C”

31

Unsafe codeUnsafe codeclass FileStream: Stream{ int handle;

public unsafe int Read(byte[] buffer, int index, int count) { int n = 0; fixed (byte* p = buffer) { ReadFile(handle, p + index, count, &n, null); } return n; }

[dllimport("kernel32", SetLastError=true)] static extern unsafe bool ReadFile(int hFile, void* lpBuffer, int nBytesToRead, int* nBytesRead, Overlapped* lpOverlapped);}

32

PropertiesProperties

Properties are “smart fields”Properties are “smart fields” Natural syntax, accessors, inliningNatural syntax, accessors, inlining

class Borrel { private int start; public int Start { get { return start; } set {

if (value < 1700 || value > 2400)

Console.WriteLine(“Invalided time”);

else

start = value; } }}

class Demo { public static Main () { Borrel b = new Borrel(); b.Start = 1745; int start = b.Start;

}}

33

IndexersIndexers

Indexers are “smart arrays”Indexers are “smart arrays” Can be overloadedCan be overloaded

class Borrel { private Dictionary participants; public Borrel() { participants = new Dictionary(); } public bool this[String name] { get { return (participants.Contains(name) && (bool)participants[name]); } set { participants.Add(name,value); } }}

class Demo { public static void Main () { Borrel b = new Borrel (); b[“Peter”] = true; Console.WriteLine(b[“Bill”]); }}

34

Dogs DemoDogs Demo Thanks Roger and Eric Sessions!

using System;

namespace VirtualDog { public class Dog { public virtual void RollOver () { Console.WriteLine("Scratch my tummy."); Bark(); }

public virtual void Bark () { Console.WriteLine("WOOF WOOF (Dog)"); } }} Imports System

Namespace VirtualDog Public Class Mopje : Inherits Dog Public overrides Sub Bark () Console.WriteLine("WOEF WOEF (Mopje)") End Sub End ClassEnd Namespace

import VirtualDog;

var d = new Dog();var m = new Mopje();

d.RollOver();m.RollOver();

35

What more?What more?

VersioningVersioning XML comments (Demo?)XML comments (Demo?) Conditional compilationConditional compilation ......

36

References and more infoReferences and more info

C# session by Tony Goodhew, C# session by Tony Goodhew, TechEd 2000TechEd 2000

.NET session Eric Meijer.NET session Eric Meijer C# session Eric MeijerC# session Eric Meijer http://www.cs.vu.nl/~pgroene/http://www.cs.vu.nl/~pgroene/

Vakken/Oop/oop.htmlVakken/Oop/oop.html

37

Questions?Questions?

38

Where do you what to go today?Where do you what to go today?