You are on page 1of 28

The .

NET Framework

The .NET Framework

Agenda
What is the .NET framework?
An overview of the CLR the .NET virtual machine
A comparison between the CLR and the JVM
A brief intro to C#
Hello World!

Page 2

Command Line
GUI

The .NET Framework

What is the .NET framework?


.NET
Application

A software platform
.NET Framework

Language neutral

Operating System +
Hardware

Provides a runtime and a set of common libraries for writing and


executing written programs in any compliant language.
The runtime is called the .NET CLR (Common Language
Runtime) similar to the Java Runtime

Page 3

The .NET Framework

Common Language Runtime


Includes a virtual machine (similar to the Java VM)
The CLR provides a secure sandboxed environment for running
MSIL (Microsoft Intermediate Language) code similar to Java
byte code.
Activates objects
Performs security checks
Allocates memory for the objects
Executes
Keeps track of references to the objects
Handles garbage collection

Page 4

The .NET Framework

Inside The .NET Framework


VB

C++

C#

J#

Common Language Specification


Windows
Forms

ADO .NET and XML


Base Class Library
Common Language Runtime

Visual Studio .NET

ASP .NET
Web Forms Web Services
Mobile Internet Toolkit

Secure, integrated class


libraries
Unifies programming
models across
languages
Enables crosslanguage integration
Factored for
extensibility
Designed for tools

Operating System

ASP.NET
High-productivity environment
for building and running
Web services
Page 5

Common Language Runtime


Executes code, maintains
security, handles component
plumbing and dependencies

The .NET Framework

The .NET Framework


A comparison with the Java platform

VB

C++

C#

J#

Common Language Specification


Windows
Forms

ADO .NET and XML


Base Class Library

Visual Studio .NET

ASP .NET
Web Forms Web Services
Mobile Internet Toolkit

Common Language Runtime


Operating System

Multiple languages Same base


class library, allowing knowledge
reuse.
Page 6

One Language

The .NET Framework

.NET Language Support


Common Language Specification

First class support for all CLS compliant languages

Microsoft provided languages

Visual Basic, C#, C++, J#, JScript

3rd-party provided languages

Page 7

APL, Cobol, Component Pascal, Eiffel, Fortran, Haskell, Mercury, Oberon,


Oz, Perl, Python, RPG, Scheme, Smalltalk, Standard ML, Ruby, Delphi and
the list is growing!

The .NET Framework

The .NET Framework Class Library


Spans All Programming Languages

Enables cross-language inheritance and debugging


Integrates well with tools

Is Object-Oriented and Consistent

Enhances developer productivity by reducing the number of


APIs to learn

Has a Built-In Common Type System

http://msdn.microsoft.com/en-us/library/zcx1eb1e(v=vs.110).aspx

Is Extensible

Makes it easy to add or modify framework features

Is Secure

Page 8

Allows creation of secure applications

The .NET Framework

Common Classes
.NET Framework Class Library

System.Web
Services
Description
Discovery
Protocols

System.Windows.Forms

UI
HtmlControls

Design

ComponentModel

WebControls
System.Drawing

Caching

Security

Drawing2D

Printing

Configuration

SessionState

Imaging

Text

System.Data

System.Xml

OleDb

SqlClient

XSLT

Common

SQLTypes

XPath

Serialization

System
Collections

IO

Security

Configuration

Net

ServiceProcess

Diagnostics

Reflection

Text

Remoting

Globalization

Resources

Threading

Serialization

Page 9

Runtime
InteropServices

The .NET Framework

Lifecycle
Compilation and Execution

Compilation
Source
Code

Language
Compiler

Native
Code

JIT
Compiler
Execution

Page 10

Code (IL)

Assembly
Metadata

At installation or the
first time each method
is called

The .NET Framework

Assemblies
ManagedModule
Module
Managed
(MSILand
andMetadata)
Metadata)
(MSIL
ManagedModule
Module
Managed
(MSILand
andMetadata)
Metadata)
(MSIL

Assembly
Assembly

Manifest
Manifest

.html
.gif

Resource Files

Page 11

Multiple Managed
Modules and
Resource Files
Are Compiled to
Produce an Assembly

The .NET Framework

The Process of Managed Execution


EXE/DLL
EXE/DLL
(MSIL
(MSILand
and

Compiler
Compiler

metadata)
metadata)
Class
Class
Libraries
Libraries
(MSIL
(MSILand
and

Class
Class Loader
Loader
JIT
JIT Compiler
Compiler
with
with optional
optional
verification
verification

metadata)
metadata)

Trusted,
pre-JITed
code only

Managed
Native
Code

Call to an
uncompiled
method

Execution
Security Checks

Page 12

Runtime Engine

Source
Source
Code
Code

The .NET Framework

Build System MS Build


The underlying build engine in Visual Studio 2005
Fully open and published XML file format for describing
build
Visual Studio 2005 build is fully customizable
You extend the build by writing managed code (tasks and
loggers)
You dont need the IDE to build Visual Studio projects
MSBuild.exe MyProj.proj /property:Configuration=Debug

Page 13

The .NET Framework

The Building Blocks


Overall architecture of MSBuild and Team Build
Team Build

.NET Framework 2.0 Redist

Web Service

Page 14

MSBuild.exe

Tasks

.TARGETS

Loggers

Visual Studio 2005


project system

Team Foundation Server

MSBuild (core components)


Engine

Loggers

Tasks

.TARGETS

.NET Framework 2.0

Source
control

Work
item
tracking

The .NET Framework

Team Build
Build Execution

Get sources from


source control

Build projects
(including code
analysis)

Run tests and


gather code
coverage

Update
work items

Publish
build outputs

Produce build
report and send
mail

Page 15

The .NET Framework

Deployment
Requires the .NET Runtime to Be Installed on Local Computer
Can Be Run Directly from a File Server or Copied Locally
Make No Registry Entries
Cannot Break Another Application
Eliminate DLL Hell
Can Be Uninstalled by Deleting Locally Copied File(s)

Page 16

The .NET Framework

ClickOnce Deployment
Windows-based rich client application deployed as a web
application.

Page 17

The .NET Framework

Application Security

.NET Framework Security Features


Code Access Security
Role-Based Security
Cryptography
Securing ASP.NET Web Applications
Securing ASP.NET Web Services

Page 18

The .NET Framework

The C# language
Very similar to Java
70% Java, 10% C++, 5% Visual Basic, 15% new
As in Java

Object-orientation (single inheritance)


Interfaces
Exceptions
Threads
Namespaces (like Packages)
Strong typing
Garbage Collection
Reflection
Dynamic loading of code
...

Page 19

As in C++
(Operator) Overloading
Pointer arithmetic in unsafe
code
Some syntactic details

The .NET Framework

New Features in C#

Really new (compared to Java)

References and output parameters


Objects on the stack (structs)
Enumerations
Unified Type System (CTS)
Versioning
Attributes

Page 20

Syntactic Sugar

Delegates
Indexers
Operator overloading
foreach statements
Boxing/unboxing

The .NET Framework

Compilation
Command Line

Assembly

Source code
Compiler
csc.exe

DLL or EXE

csc /out:parceltracker.dll /debug+ /target:library parceltracker.cs


Page 21

The .NET Framework

Hello C# World
Command Line
File HelloWorld.cs
using System;
class HelloWorld
{
static void Main()
{
Console.WriteLine("Hello, C# World");
}
}

Page 22

uses
usesthe
thenamespace
namespace
System
System
entry
entrypoint
pointmust
mustbe
be
called
calledMain
Main
output
outputgoes
goestotothe
the
console
console
file
filename
nameand
andclass
class
name
name
need
neednot
notbe
beidentical
identical

The .NET Framework

Compiler Options
Command Line
Compile Directly from a Command Prompt Window
C:\>csc
C:\>csc HelloWorld.cs
HelloWorld.cs

Use /t to indicate target

C:\>csc
C:\>csc /t:exe
/t:exe HelloWorld.cs
HelloWorld.cs

C:\>csc
/t:exe
/reference:assemb1.dll
HelloWorld.cs
Use
/reference
to reference
assemblies
C:\>csc
/t:exe
/reference:assemb1.dll
HelloWorld.cs

Page 23

The .NET Framework

Compiling
Visual Studio

Page 24

The .NET Framework

Hello World
GUI

public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
}
private void buttonSayHello_Click(object sender,
EventArgs e)
{
MessageBox.Show("Hello World!");
}
}
Page 25

The .NET Framework

Further reading
The C# Language Specification ECMA 334
Professional C# 2005
C# 2.0, The Complete Reference Herbert Schildt
Professional .NET Framework 2.0 Joe Duffy

Good links
http://www.c-sharpcorner.com
http://www.thecodeproject.com
http://windowsforms.net
http://www.gotdotnet.com/
http://msdn.microsoft.com/netframework/using/

Page 26

The .NET Framework

Summary
What You Did
Write a command line
client
Write a GUI client

Page 27

What You Learned


An overview of the .NET
framework
An introduction to the C#
programming language

End of Lesson