Slide 1

Slide 1 text

Introduction to .NET

Slide 2

Slide 2 text

Agenda ●Three views of .NET ●Programming Language Buffet ●Memory Management ●CIL and the JIT compiler

Slide 3

Slide 3 text

Three Views of .NET ●Common Language Specification ●Common Language Runtime ●Application Framework

Slide 4

Slide 4 text

Common Language Specification ●Specifies a common type system ●Ensures language interoperability ●Code can but does not have to conform to CLS ○uint is not a CLS compliant type, but exists in C# ●Allows for a wide variety of languages to be built to run in the same environment

Slide 5

Slide 5 text

Common Language Runtime ●Where Common Intermediate Language (CIL) code is compiled into native code ○This means that you do not have to have different builds to optimize for different types of hardware ○Your code is more portable ●Provides garbage collection services ●Supports uniform exception handling

Slide 6

Slide 6 text

Application Framework ●Common libraries focused on developer productivity ●Used to build different types of applications: ○Win32-based client applications (WinForms, WPF) ○Windows Services (WCF) ○Web Services ("classic" web services, WCF) ○Web Applications (ASP.NET, ASP.NET MVC) ○RIA applications (Silverlight)

Slide 7

Slide 7 text

Application Framework (cont.) ○XBox Games (XNA) ○Mobile Apps for WP7 ○Metro Apps (Windows 8)

Slide 8

Slide 8 text

Programming Language Buffet ●Because of the CLS, many different languages have been built to run on the CLR ●Some examples: ○C#, C++/CLI, VB.NET, F#, IronPython, IronRuby, Powershell ●It is not uncommon to build different parts of a single application in different languages, based on requirements ●You can even use multiple languages to build a single library (DLL)

Slide 9

Slide 9 text

Polyglot Example ●Polyglot: Written in several languages ●A Win32 application using: ○F# for business rule processing ○C# for business modeling, data access APIs, and GUIs ○VB.NET for MS Office interoperability layer

Slide 10

Slide 10 text

Memory Management ●The CLR manages memory allocation and deallocation ○The new call in C# asks the CLR to find a location in memory large enough for your object ○The CLR may or may not allocate new memory blocks for this purpose ○The returned value is a reference that is tracked by the CLR ○When all references to a single object fall out of scope, that object is a candidate for garbage collection

Slide 11

Slide 11 text

Memory Management ●This means: ○new is a cheap operation ○Garbage collection cleans up after your object, so you do not need to call delete ○Garbage collection occurs outside your control, so you do not know when an object will be deallocated ○If you do not control when garbage collection happens, how do you know when to release any unmanaged resources?

Slide 12

Slide 12 text

The Dispose Pattern ●Holding unmanaged resources (such as a database connection) is a common problem ●To use the pattern, implement IDisposable ●Call the IDisposable.Dispose() method as soon as possible ●Can tell the garbage collector to ignore this class when it runs ●C# provides some nice language constructs that make using the Dispose pattern even easier

Slide 13

Slide 13 text

CIL and the JIT compiler ●All high-level language code is compiled into a Common Intermediate Language (CIL) ●Formerly known as Microsoft Intermediate Language (MSIL) ●The runtime compiles the CIL into native code just-in-time (JIT) at runtime ●Optimizes for the capabilities of the machine (e.g., SSE extensions, 3D Now!, etc.) ●This means that the code you write today will run faster on tomorrow's hardware without a recompile or redistribution ●This means that you do not have to have different optimized builds when you ship your application

Slide 14

Slide 14 text

Summary ●.NET has many aspects - the CLR, the CLS, and the application framework ●.NET encourages the use of the right language for the job, even multiple languages for a single application ●.NET enables developers to be incredibly productive by managing some of the more difficult aspects of programs, such as memory management ●.NET provides a JIT compiler with the CLR that ensures that applications developed in .NET are optimized to the greatest extent possible