Introducing the .NET Framework with C_ by linzhengnd


									Introducing the .NET Framework
with C#
      New Official Title!

                      Student Ambassador

Main Entry: am·bas·sa·dor
Pronunciation: am-'ba-s&-d&r, &m-, im-, -"dor, -'bas-d&r
Function: noun
1 : an official envoy; especially : a diplomatic agent of the highest rank accredited to a foreign government or
sovereign as the resident representative of his own government or sovereign or appointed for a special and often
temporary diplomatic assignment

2 a : an authorized representative or messenger b : an unofficial representative <traveling abroad as ambassadors of
Why is Microsoft Doing This?
• Make Microsoft tools and technology
• Provide awareness and training opportunities
• To LEARN from student developers
Win the hearts and minds of
Student Ambassador Program
Required Activities
• Deliver Tech Talks
   – 6 Minimum with 30 student attendees per talk
   – collect & submit evals
• Start a .NET User Group
   – Focused on a specific area of .NET or Microsoft
• Support Campus Launch Events
• Support Local Field Activities
• Drive Awareness of MSDNAA
Student Ambassador Program
Optional Activities
• Host a Student Programming Contest
• Student User Group Projects
   – Limited number of opportunities
   – Need project proposals ASAP
Defining the .NET Framework

• The .NET Framework is
  – A software development environment
  – A runtime engine for Managed Code
  – A platform designed for Internet-Distributed
• The .NET Framework is an exciting new
  computing platform
What is the .NET Framework
• A new computing platform designed to
  simplify application development
• A consistent object-oriented programming
• A code-execution environment that:
  – Minimizes software deployment and versioning
  – Eliminates the performance problems of scripted
    or interpreted environments
Primary Components of .NET
• .NET Framework Class Libraries
  – Object-oriented collection of reusable types
  – Sits on-top of the Common Language Runtime
• Common Language Runtime (CLR)
  – Manages code execution at runtime
  – Memory management, thread management, etc.
  – Code designed for the CLR is referred to as
    “Managed Code”
Inside the .NET Framework
VB   C++    C#     J#    Python     …
 Web Services           User Interface
                                         High-productivity environment
              ASP.NET                    for building and running Web
            Data and XML

           Base Framework
                                         Secure, integrated class
 Common Language Runtime (CLR)           libraries
                                         •Unifies programming models
           Operating System              across languages
                                         •Enables cross-language
 Common Language
 Runtime                                 •Factored for extensibility

 Executes code, maintains                •Designed for tools
 security, handles component
 “plumbing” and dependencies
One Runtime For Many Languages

•   CLR is an open standard
•   Any language can make use of CLR services
•   Any language can use classes written in any
    other language
•   Any language can inherit classes written in any
    other language
.NET Framework Class Libraries
• Sit on top of the CLR
• Reusable types that tightly integrate with the
• Object oriented – inheritance, polymorphism,
• Provide functionality for ASP.NET, XML Web
  Services, ADO.NET, Windows Forms, basic
  system functionality (IO, XML, etc.)
The Common Language Runtime
• Code that targets the CLR is referred to as
  managed code
• All managed code has the features of the
  –   Object Oriented
  –   Cross-language integration
  –   Cross language exception handling
  –   Multiple version support (no more DLL Hell)
The Common Language Runtime
• The CLR manages object layout and references to
• Objects whose lifetimes are managed by the CLR are
  referred to as Managed Data
• Automatic memory management reduces memory
• In managed code you can use:
   – Managed Data
   – Unmanaged data
   – Both
The Common Language Runtime
• All CLR-compliant compilers use a common type
   – Allows for cross-language inheritance
   – Passing object instances across language barriers
   – Invoking methods across language barriers
• Managed components expose metadata
• Metadata includes
   – Resources component was compiled against
   – Information about types and dependencies (no more
Internet Distributed Software

   (database or             Second-Tier   Second-Tier
   other server)

             Web Server                   Web Server

                   Client                   Client
Managed Code and the CLR

• The Common Language Runtime (CLR) is a runtime
  – Manages .NET Code (such as C# applications)
  – Provides features such as memory management, thread
    management, object type safety, security, etc.
  – Is a part of the .NET Framework
• Managed code
  – Code that targets the CLR
  – Any .NET Language, including C#, Visual Basic, C++, Java,
    Cobol, etc.
 The CLR and Managed Code

                                         Managed Executable
   Legacy          Managed Components
(unmanaged code)
                            Common Language Runtime
                       (JIT compilation, memory management, etc.)

                    (or other operating oystem)
IL and Metadata
• All Managed executables consist of
   – Intermediate Language (IL) instructions
   – Metadata
• IL
   – CPU independent machine language
   – Just-in-time compiled at runtime
• Metadata
   – Structured information
   – describes programming constructs including
       • Classes definitions, field and method definitions, parameter
         lists, return types, etc.
From Source Code to Managed .exe
     using System.Windows.Forms;
     using System.Drawing;

     class MyForm:Form{
        public static void Main(){
              new MyForm());
        }                                          C# Compiler
       protected override
          void OnPaint(
          PaintEventArgs e){
             "Hello World!",
             new Font("Arial",35),
             Brushes.Blue, 10,                   SomeSources.exe


                                   A Managed
                                   Application       IL
Just-in-Time Compiling

• All managed code runs in native machine
• However, all managed code is made up of IL and
• The CLR JIT-compiles the IL and metadata
   – At execution time
   – Executed directly by CPU
• Allows for the best of both worlds
   – Code management features
   – Performance of full-speed execution
Executing a Managed Application
                          At execution time the IL and
                           Metadata are JIT compiled

        Metadata          Running Process’ Memory

                            JIT Compiler

                                        Machine Language
                             10010100 10110000 10000000 10111010
                             11011011 11010111 11000010 01110110

                     The CPU executes the JIT-
                   compiled machine code directly
Automatic Memory Management

 • The CLR manages memory for managed code
    – All allocations of objects and buffers made from a Managed
    – Unused objects and buffers are cleaned up automatically
      through Garbage Collection
 • Some of the worst bugs in software development are
   not possible with managed code
    – Leaked memory or objects
    – References to freed or non-existent objects
    – Reading of uninitialized variables
 • Pointerless environment
Garbage Collection
   class MyClass{
      void Method(){
         Variable v1;        The Managed Heap
         Variable v2;

         do{                                  B
         .                        A

Objects A and D will                              E
be cleaned up because
 neither is directly or                   D
 indirectly referenced
        by code

           = Object or buffer in memory
Cross Language Support
• The .NET Framework supports many languages
• Any compiler can be modified to emit managed executables
   – IL and metadata
• Languages that target the .NET Framework
   – C#, Visual Basic, C++, Java, PERL, COBOL, SmallTalk
   – Dozens more existing and on the way
• Regardless of source language, all managed code can
   – Use the same tools
   – Use the same reusable components
   – Take advantage of features of the CLR
• Developers use their language of choice
Visual Studio.NET

• A Integrated Development Environment
  – To develop managed and unmanaged
  – Supports C#, C++, Visual Basic, JavaScript
  – Many useful tools and wizards
• Not part of the .NET Framework
  – Not necessary to build or run managed code
  – The .NET Framework SDK includes command line
The Framework Class Library
• A huge collection of reusable types
   – Classes, interfaces, enumerations and structures
• For use by any managed code
   – Including code written in any managed programming
• Types for
   – Common tasks such as collections, file IO, memory and
     thread management
   – GUI and window manipulation
   – Web form and web service applications
• Totally object oriented toolbox for developers
   – Ships as part of the .NET Framework
Using the FCL

• Types are arranged in a hierarchy of Namespaces
• A type’s full name includes its namespaces
   – Form class is actually System.Windows.Forms.Form
   – Use using to indicate namespaces in source code
• Assembly references are necessary for many types
• The SDK documentation is critical for using SDK
   – Includes descriptions
   – Often includes useful code samples
   – Indicates namespaces and assemblies for types
Distributing Managed Code

 (database or             Second-Tier   Second-Tier
 other server)

           Web Server                   Web Server

                 Client                   Client
Managed Execution Process
public void Fill()
  DotNetJunkies.StudyGroupPortal.Data.EventDB eDB
    = new DotNetJunkies.StudyGroupPortal.Data.EventDB();
  //Create a data reader
  IDataReader reader = eDB.GetEventByGuid(_guid);
  //Advance to the first record in the reader
  reader.Read();                                           Language Specific Compiler
  //Populate this instance of the Event class
  this.CreateEvent(ref reader);
  //Close the reader

Compilation And Execution

Source    Language      Code (IL)
 Code     Compiler      Metadata
Microsoft Intermediate Language
• Managed code is compiled to MSIL
• CPU-independent set of instructions
  – Loading, storing, initializing and calling methods
  – Arithmetic and logical operations, etc.
  – Control flow, exception handling, direct memory
• Contains MSIL code to be executed
• Security boundary – permissions are granted
  at the assembly level
• Type boundary – all types include the
  assembly name they are a part of
• Self-describing manifest – metadata that
  describes the types in the assembly
• Smallest versionable unit in the CLR
• Deployment unit
Just-In-Time Compiling
• Assemblies are compiled to native code by a
  Just-In-Time (JIT) compiler
• Compiled assemblies include metadata
• No Type Libraries or Interface Definition
  Language (IDL)
Compilation And Execution

Source         Language           Code (IL)
 Code          Compiler           Metadata

  Native                 JIT
  Code                 Compiler    Before installation or
                                    the first time each
           Execution                 method is called
Just-In-Time Compiling
• All assemblies must be compiled to native
  code before executing
• JIT compilers are built into the CLR for every
  supported CPU architecture
• JIT compilers convert MSIL to native on
• Resulting native code is stored for reuse
• JIT compiling occurs for each method after
  the application is restarted
• .NET Framework is a code execution platform
• .NET Framework consists of two primary parts: .NET
  Class Libraries, Common Language Runtime
• All CLR-compliant compilers support the common
  type system
• Managed code is object oriented
• Managed code is compiled to and assembly (MSIL)
  by language specific compiler
• Assemblies are compiled to native code by JIT
Contact Information
• Alejandro Simon
• Talks Web Page:
• E-Mail:

To top