Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.


1.521 Aufrufe

Veröffentlicht am

  • Als Erste(r) kommentieren


  1. 1. Introducing the .NET Framework with C# Global Computer Center
  2. 2. Assemblies Assemblies are the physical packaging of the class libraries. These are .dll files, but don't confuse them with Win32 shared libraries. Examples are mscorlib.dll System.dll System.Data.dll Accessibility.dll Note that namespaces are often distributed among several assemblies
  3. 3. Defining the .NET Framework <ul><li>The .NET Framework is </li></ul><ul><ul><li>A software development environment </li></ul></ul><ul><ul><li>A runtime engine for Managed Code </li></ul></ul><ul><ul><li>A platform designed for Internet-Distributed software </li></ul></ul><ul><li>The .NET Framework is an exciting new computing platform </li></ul>
  4. 4. Internet Distributed Software Web Server Client Client Web Server Second-Tier (database or other server) Second-Tier Second-Tier
  5. 5. A First Look at Managed Code using System.Windows.Forms; using System.Drawing; class MyForm:Form{ public static void Main(){ Application.Run(new MyForm()); } protected override void OnPaint(PaintEventArgs e){ e.Graphics.DrawString(&quot;Hello World!&quot;, new Font(&quot;Arial&quot;, 35), Brushes.Blue, 10, 100); } } HelloGUI.cs c:> csc /target:winexe HelloGui.cs
  6. 6. Demo HelloGUI.cs
  7. 7. Managed Code and the CLR <ul><li>The Common Language Runtime (CLR) is a runtime engine </li></ul><ul><ul><li>Manages .NET Code (such as C# applications) </li></ul></ul><ul><ul><li>Provides features such as memory management, thread management, object type safety, security, etc. </li></ul></ul><ul><ul><li>Is a part of the .NET Framework </li></ul></ul><ul><li>Managed code </li></ul><ul><ul><li>Code that targets the CLR </li></ul></ul><ul><ul><li>Any .NET Language, including C#, Visual Basic, C++, Java, Cobol, etc. </li></ul></ul>
  8. 8. The CLR and Managed Code Windows (or other operating oystem) Common Language Runtime (JIT compilation, memory management, etc.) Legacy Software (unmanaged code) Managed Executable Reusable Managed Components
  9. 9. IL and Metadata <ul><li>All Managed executables consist of </li></ul><ul><ul><li>Intermediate Language (IL) instructions </li></ul></ul><ul><ul><li>Metadata </li></ul></ul><ul><li>IL </li></ul><ul><ul><li>CPU independent machine language </li></ul></ul><ul><ul><li>Just-in-time compiled at runtime </li></ul></ul><ul><li>Metadata </li></ul><ul><ul><li>Structured information </li></ul></ul><ul><ul><li>describes programming constructs including </li></ul></ul><ul><ul><ul><li>Classes definitions, field and method definitions, parameter lists, return types, etc. </li></ul></ul></ul>
  10. 10. From Source Code to Managed .exe C# Compiler A Managed Application This Cod is output with Manifest Into a PE (Portably Executable ) File using System.Windows.Forms; using System.Drawing; class MyForm:Form{ public static void Main(){ Application.Run( new MyForm()); } protected override void OnPaint( PaintEventArgs e){ e.Graphics.DrawString( &quot;Hello World!&quot;, new Font(&quot;Arial&quot;,35), Brushes.Blue, 10, 100); SomeSource.cs SomeSources.exe IL Metadata
  11. 11. Just-in-Time Compiling <ul><li>All managed code runs in native machine language </li></ul><ul><li>However, all managed code is made up of IL and metadata </li></ul><ul><li>The CLR JIT-compiles the IL and metadata </li></ul><ul><ul><li>At execution time </li></ul></ul><ul><ul><li>Executed directly by CPU </li></ul></ul><ul><li>Allows for the best of both worlds </li></ul><ul><ul><li>Code management features </li></ul></ul><ul><ul><li>Performance of full-speed execution </li></ul></ul>
  12. 12. Executing a Managed Application Running Process’ Memory JIT Compiler 10010100 10110000 10000000 10111010 11011011 11010111 11000010 01110110 Native Machine Language The CPU executes the JIT- compiled machine code directly At execution time the IL and Metadata are JIT compiled SomeSources.exe IL Metadata
  13. 13. Automatic Memory Management <ul><li>The CLR manages memory for managed code </li></ul><ul><ul><li>All allocations of objects and buffers made from a Managed Heap </li></ul></ul><ul><ul><li>Unused objects and buffers are cleaned up automatically through Garbage Collection </li></ul></ul><ul><li>Some of the worst bugs in software development are not possible with managed code </li></ul><ul><ul><li>Leaked memory or objects </li></ul></ul><ul><ul><li>References to freed or non-existent objects </li></ul></ul><ul><ul><li>Reading of uninitialized variables </li></ul></ul><ul><li>Pointerless environment </li></ul>
  14. 14. Garbage Collection A B E D C The Managed Heap = Object or buffer in memory class MyClass{ void Method(){ Variable v1; Variable v2; do{ . . . Objects A and D will be cleaned up because neither is directly or indirectly referenced by code
  15. 15. Cross Language Support <ul><li>The .NET Framework supports many languages </li></ul><ul><li>Any compiler can be modified to emit managed executables </li></ul><ul><ul><li>IL and metadata </li></ul></ul><ul><li>Languages that target the .NET Framework </li></ul><ul><ul><li>C#, Visual Basic, C++, Java, PERL, COBOL, SmallTalk </li></ul></ul><ul><ul><li>Dozens more existing and on the way </li></ul></ul><ul><li>Regardless of source language, all managed code can </li></ul><ul><ul><li>Use the same tools </li></ul></ul><ul><ul><li>Use the same reusable components </li></ul></ul><ul><ul><li>Take advantage of features of the CLR </li></ul></ul><ul><li>Developers use their language of choice </li></ul>
  16. 16. Visual Studio.NET <ul><li>A Integrated Development Environment </li></ul><ul><ul><li>To develop managed and unmanaged applications </li></ul></ul><ul><ul><li>Supports C#, C++, Visual Basic, JavaScript </li></ul></ul><ul><ul><li>Many useful tools and wizards </li></ul></ul><ul><li>Not part of the .NET Framework </li></ul><ul><ul><li>Not necessary to build or run managed code </li></ul></ul><ul><ul><li>The .NET Framework SDK includes command line compilers </li></ul></ul>
  17. 17. Demo Visual Studio.NET
  18. 18. The Framework Class Library <ul><li>A huge collection of reusable types </li></ul><ul><ul><li>Classes, interfaces, enumerations and structures </li></ul></ul><ul><li>For use by any managed code </li></ul><ul><ul><li>Including code written in any managed programming language </li></ul></ul><ul><li>Types for </li></ul><ul><ul><li>Common tasks such as collections, file IO, memory and thread management </li></ul></ul><ul><ul><li>GUI and window manipulation </li></ul></ul><ul><ul><li>Web form and web service applications </li></ul></ul><ul><li>Totally object oriented toolbox for developers </li></ul><ul><ul><li>Ships as part of the .NET Framework </li></ul></ul>
  19. 19. Using the FCL <ul><li>Types are arranged in a hierarchy of Namespaces </li></ul><ul><li>A type’s full name includes its namespaces </li></ul><ul><ul><li>Form class is actually System.Windows.Forms.Form </li></ul></ul><ul><ul><li>Use using to indicate namespaces in source code </li></ul></ul><ul><li>Assembly references are necessary for many types </li></ul><ul><li>The SDK documentation is critical for using SDK types </li></ul><ul><ul><li>Includes descriptions </li></ul></ul><ul><ul><li>Often includes useful code samples </li></ul></ul><ul><ul><li>Indicates namespaces and assemblies for types </li></ul></ul>
  20. 20. Demo The FCL SDK
  21. 21. Types of Managed Applications <ul><li>Common application </li></ul><ul><ul><li>GUI or windowed applications (Windows.Forms) </li></ul></ul><ul><ul><li>Console applications or command line apps </li></ul></ul><ul><li>Web applications (ASP.net) </li></ul><ul><ul><li>Web forms applications </li></ul></ul><ul><ul><li>Web services </li></ul></ul><ul><li>Scripted code </li></ul><ul><ul><li>Applications like word processors or database servers can host the CLR </li></ul></ul><ul><ul><li>Use any managed language (C#, VB, etc.) as a script or macro language </li></ul></ul><ul><li>Wherever you use managed code </li></ul><ul><ul><li>Same compilers and tools </li></ul></ul><ul><ul><li>Same FCL </li></ul></ul><ul><ul><li>Same CLR (JIT compiled, object oriented, memory managed, etc.) </li></ul></ul>
  22. 22. Distributing Managed Code Web Server Client Client Web Server Second-Tier (database or other server) Second-Tier Second-Tier
  23. 23. Demo Draw.aspx
  24. 24. Introducing the .NET Framework with C#
  25. 26. Class Library The class library provides a comprehensive set of facilities for application development. Primarily written in C#, it can be used by any language, thanks to the Common Language Specification . The class library is structured into Namespaces, and deployed in shared libraries known as Assemblies. When we speak of the .NET framework , we are primarily referring to this class library.
  26. 27. Namespaces Namespaces are a mechanism for logically grouping similar classes into a hierarchical structure. This prevents naming conflicts. The structure is implemented using dot-separated words. The top level namespace for most of the .NET framework is System . Under the System namespace you'll find the following: System.IO System.Net System.Net.Sockets System.Reflection System.Threading ...and many others. There are other top-level namespaces as well; Accessibility , and Windows are examples. You can also create your own namespaces: just prefix them with the name of your organization. Microsoft.VisualBasic is an example.
  27. 28. Common Language Specification (CLS): 1)The Common Language Specification (CLS) describes a set of features that different languages have in common. The CLS includes a subset of the Common Type System (CTS). 2)The CTS makes available a common set of data types so that compiled code of one language could easily interoperate with compiled code of another language by understanding each others’ data types. 3)The common type system is a rich type system, built into the common language runtime, that supports the types and operations found in most programming languages. The common type system supports the complete implementation of a wide range of programming languages. 4)common type system this is used to communicate with other language. example in vb we have int and in c++ we have long so that in one case they are not compatiable with each other so that CTS palys important role with using System.int32