This document provides an overview of the .NET framework and common type system. It discusses key concepts like value types, reference types, inheritance, polymorphism, interfaces, boxing and unboxing. It also covers working with types in .NET like type operators, conversions, casting and managing external types. The document is divided into multiple modules that cover topics such as the .NET framework architecture, common language runtime, deployment, and common type system fundamentals.
3. Overview of the Microsoft .NET framework
• The .NET framework
• Common language runtime
• The .NET framework class library
• ADO.NET: Data and XML
• XML Web service
• Web forms and services
22. Demonstration: Hello World
• Compile the source code from Visual Studio .NET Command Promt
csc HelloDemoCS.cs
• Running the resulting executable file and see the output
Hello World using C#!
• Viewing assembly metadata by using MSIL (ildasm.exe)
31. The Process of Managed Execution
• Compilation outputs an executable module (PE – portable executable)
• Microsoft Intermediate Language (MSIL): CPU-independent set of instructions
that can be converted to native code efficiently
• Type Metadata: types, members, references used by CLR at runtime
• Resources: .jpg, .bmp, .wav,…
• When a user executes a managed application:
• Operating System loads CLR
• CLR converts MSIL instructions to native code (only when needed - JIT)
• JIT improve the memory usage and initialization time
34. Microsoft Intermediate Language
• MSIL is a CPU-independent language
• MSIL contains instructions for many common operations:
• Creating and initializing objects
• Calling methods
• Arithmetic and logical operations
• Control flow
• Memory access
• Exception handling
• …
• MSIL must be converted to CPU-specific (native) code by a JIT
compiler
39. Just-In-Time Compilation
• The code execution process
• CLR loads class types and attach stub code to each method (can be
considered as kind of pseudo-code)
• For subsequent method calls, the stub directs program execution to CLR for
compiling the method’s MSIL to native code
• The stub code is replaced by the address of compiled native code
• Future calls to a compiled method will not involve the JIT compiler
47. Windows Forms
• To develop applications in which the client computer handles most of
the application processing
• System.Windows.Forms contains classes used to create Windows
forms
48. Web Forms
• To create applications in which the primary user interface is a browser
• Web Forms applications are platform-independent
• System.Web contains classes to create Web Forms
49. XML Web Services
• A programmable entity residing on a Web server and is exposed
through standard Internet protocols
• Programming using XML web services is similar to using COM-based
component (local library)
• XML web services are using SOAP for transferring messages from/to a
Web server, SOAP is almost transparent to the developer
51. Creating a Simple .NET Framework
Component
• The component provides a simple wrappers for string array
• String GetString(int i): return the string at index i
• Read-Only Count: number of strings in the array
• Structured exception handling
71. Common Concepts
• Class libraries are organized
in hierarchical namespaces
and stored in PE files (dll,
exe)
• A PE file may contain
multiple namespaces and
vice versa
• Metadata describes all the
classes and types
• PE files and non-executable
files are combined in to a
assembly file
• Metadata describes files in
one assembly file, exported
and imported classes and
types
72. Simple Applications
• A simplest .NET app can be
executed on any computer as
long as .NET runtime is
installed
• No registry, no external dll,
no registration… (like
COM/COM++ or old DLL-
based software)
79. A Strong-Named Assembly
• A component may be shared
among many unrelated
applications. That
component should be
strongly named and located
in the OS assembly cache
• Let’s discuss about dll-
sharing in the conventional
way
• How to call API
dynamically
• How the dll is located
• What are the
disadvantages
• Let’s discuss about COM-
based dll sharing
93. An Introduction to Common Type System
• Value Types
• Reference Types
• Fields, Methods and Properties
• Interfaces: merely description of methods, properties and events
128. Type Operators
• is: determine if an object is of a specific type
• as: convert an object to a specific type, if type is not matched null is
return (it’s different from casting)
• typeof: return the type of an object
131. How Boxing Works
• Boxing:
• A value type is coped from the stack to the heap
• An object is allocated on the heap to store the value
• Unboxing:
• Value is coped from the heap to a variable on the stack
• InvalidCastException may occur