.NET Overview Objectives Introduce .NET overview languages - - PDF document

net overview objectives
SMART_READER_LITE
LIVE PREVIEW

.NET Overview Objectives Introduce .NET overview languages - - PDF document

.NET Overview Objectives Introduce .NET overview languages libraries development and execution model Examine simple C# program 2 .NET Overview .NET is a sweeping marketing term for a family of products


slide-1
SLIDE 1

.NET Overview

slide-2
SLIDE 2

Objectives

2

  • Introduce .NET

– overview – languages – libraries – development and execution model

  • Examine simple C# program
slide-3
SLIDE 3

.NET Overview

  • .NET is a sweeping marketing term for a family of products

– development tools and languages – platform – application management servers – value-added services

3

development platform servers services Languages Compilers Visual Studio .NET Common Language Runtime Framework Libraries SQL Server BizTalk SharePoint ... My Services Alerts Passport ...

slide-4
SLIDE 4

Evolution of the platform

4

  • .NET is the next evolutionary step for the Microsoft platform

– new languages largely replace classic C++ and Visual Basic – new runtime model reduces need for COM style integration – XML web services used in place of DCOM – Windows Forms replace MFC – ASP.NET improves on ASP – etc.

slide-5
SLIDE 5

Software development

5

  • .NET software development and execution has many actors

– languages – libraries – compilers – intermediate language – execution engine

slide-6
SLIDE 6

Languages

6

  • Many .NET programming languages available

– C# – VB.NET – C++ – etc.

  • Language choice typically based on many factors

– programmer background – problem domain – language features – corporate mandate

slide-7
SLIDE 7

Language power

  • All languages can access .NET infrastructure

7

C# class Hello { static void Main() { System.Console.WriteLine("hello"); } } VB.NET Class Goodbye Shared Sub Main() System.Console.WriteLine("goodbye") End Sub End Class

slide-8
SLIDE 8

Language interoperability

  • All .NET languages can interoperate

C# calling VB.NET class Hello { static void Main() { System.Console.WriteLine(Greeting.Message()); } } Class Greeting Shared Function Message() As String Return "hello" End Function End Class

8

slide-9
SLIDE 9

Language variability

  • Not all .NET languages have exactly the same capabilities

– differ in small but important ways

C# VB.NET class Hello { static void Main() { int i; uint u; } } Class Greeting Shared Sub Main() Dim i as Integer End Sub End Class signed integer unsigned integer signed integer only

9

slide-10
SLIDE 10

Common Language Specification

  • Common Language Specification (CLS) defines type subset

– required to be supported by all .NET languages – limiting code to CLS maximizes language interoperability – code limited to CLS called CLS compliant

10

public class Calculator { public uint Add(uint a, uint b) { return a + b; } } not CLS compliant to use uint in public interface of public class

slide-11
SLIDE 11

Library

  • Extensive set of standard libraries available

– for wide range of application types – called .NET Framework class library

.NET Framework class library

Collections Web development Input/Output Database access Windows Forms GUI Networking XML processing Threading Reflection Debugging 11

slide-12
SLIDE 12

Compilation

  • Compilers produce Intermediate Language (IL)

– IL is not executable – similar to assembly language – processor independent

C# code

12

VB.NET code <other> code C# compiler VB.NET compiler <other> compiler IL IL IL

slide-13
SLIDE 13

IL

  • C# compiler translates C# source code into IL

C# source IL

.locals init ([0] class Calc c, [1] int32 sum) newobj instance void Calc::.ctor() stloc.0 // c = ptr to new object ldloc.0 ldc.i4.2 // pass second arg ldc.i4.4 // pass first arg callvirt instance int32 Calc::Add(int32,int32) stloc.1 // sum = retval Calc c = new Calc(); int sum = c.Add(2, 4);

C# compiler

13

slide-14
SLIDE 14

Execution engine

  • Common Language Runtime (CLR) is the execution engine

– loads IL – compiles IL – executes resulting machine code

14

CLR

IL

Runtime compiler Execute

machine code

slide-15
SLIDE 15

JIT runtime compile

15

  • IL is compiled into machine code at runtime by the CLR

– compiles methods as needed – called just in time (JIT) compile

  • JIT compilation model:

– first time method is called the IL is compiled and optimized – compiled machine code is cached in transient memory – cached copy used for subsequent calls

Cache IL code F() G() H()

JIT runtime compiler Execute machine code for F()

slide-16
SLIDE 16

NGEN install time compile

  • Can compile IL into machine code when app installed

– use native image generator ngen.exe – can speed startup time since code pre-compiled – but cannot do as many optimizations – original IL must still be available for type information

16

CLR native image cache Execute ngen

IL machine code

slide-17
SLIDE 17

Execution command

  • CLR automatically invoked when .NET application executed

C:\> MyApp hello

execute

17

slide-18
SLIDE 18

Required CLR

  • CLR and .NET Framework required to run .NET app

– will be incorporated into Windows and service packs – developers install as part of .NET Framework SDK – users can run dotnetredist.exe

18

slide-19
SLIDE 19

C# program

MyApp.cs

  • C# program basics

– source file has .cs extension – namespace used to group related types – class defines new type – Main is application entry point – WriteLine writes output – { and } delimit code block

19

namespace MyNamespace { class MyApp { static void Main() { System.Console.WriteLine("hello"); } } }

slide-20
SLIDE 20

Building console executable

20

  • Can use C# compiler to build console executable

– use /t[arget]:exe – use /out:<name> to specify output file name

  • Default values can simplify use

– default target type is console executable – default name adds .exe to base name of file containing Main

C:\> csc /target:exe /out:MyApp.exe MyApp.cs explicit

  • ptions

C:\> csc MyApp.cs implicit

  • ptions
slide-21
SLIDE 21

Building Windows executable

  • Can use C# compiler to build windows executable

– use /t[arget]:winexe

21

C:\> csc /target:winexe MyWinApp.cs build Windows application

slide-22
SLIDE 22

Building library

  • Can use C# compiler to build library

– use /t[arget]:library

  • Controlling output file name:

– can use /out:<name> to specify output file name – default: adds .dll to base name of first input file

22

C:\> csc /target:library /out:MyLib.dll MyLib.cs create library

slide-23
SLIDE 23

Summary

23

  • .NET requires multiple steps to develop and run software

– code in one of the many .NET languages – compile into IL – install the CLR – execute

  • CLR JIT compiles IL at runtime

– always executes compiled code – never interpreted

  • Can target CLS compliance

– to maximize language interoperability