100% found this document useful (1 vote)
664 views

C# Notes

The document provides an overview of the .NET Framework, including its architecture and key components like the Common Language Runtime (CLR) and managed code. It describes how .NET applications are compiled and executed, and the role of assemblies and metadata.

Uploaded by

Somnath Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
664 views

C# Notes

The document provides an overview of the .NET Framework, including its architecture and key components like the Common Language Runtime (CLR) and managed code. It describes how .NET applications are compiled and executed, and the role of assemblies and metadata.

Uploaded by

Somnath Sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

.

NET Framework Overview


.NET Framework, CLR, MSIL, Assemblies, CTS, etc.

Doncho Minkov
Technical Trainer
http://www.minkov.it
Telerik School Academy
schoolacademy.telerik.com
Table of Contents
1. What is .NET?
 Microsoft .NET platform architecture
1. What is .NET Framework?
 .NET Framework Architecture
1. Common Language Runtime (CLR)
2. Managed Code
3. Intermediate Language MSIL
4. Assemblies and Metadata
5. .NET Applications
Table of Contents (2)
8. Common Language Infrastructure (CLI) and
integration of different languages
 Common Language Specification (CLS)
 Common Type System (CTS)
8. Framework Class Library
9. Integrated Development Environment Visual
Studio
.NET Framework
Microsoft's Platform for
Application Development
What is the .NET Platform?
 The .NET platform

 Microsoft's platform for software development


 Unified technology for development of almost
any kind of applications
 GUI / Web / RIA / mobile / server / cloud / etc.
 .NET platform versions

 .NET Framework
 Silverlight / Windows Phone 7
 .NET Compact Framework
What is .NET Framework?
 .NET Framework

 An environment for developing and


executing .NET applications
 Unified programming model, set of languages,
class libraries, infrastructure, components and
tools for application development
 Environment for controlled execution of
managed code
 It is commonly assumed that

 .NET platform == .NET Framework


.NET Framework Components
 Common Language Runtime (CLR)

 Environment for controlled execution of


programmed code – like a virtual machine
 Executes .NET applications
 Framework Class Library (FCL)

 Standard class library for .NET development


 Delivers basic functionality for developing: XML,
ADO.NET, LINQ, ASP.NET, WPF, WCF, WWF,
Silverlight, Web services, Windows Forms, ...
 SDK, compilers and tools
.NET Framework Architecture
 The OS manages the resources, the
processes and the users of the machine
 Provides to the applications some
services (threads, I/O, GDI+, DirectX,
COM, COM+, MSMQ, IIS, WMI, …)
 CLR is a separate process in the OS

Operating System (OS)


.NET Framework Architecture (2)

 CLR manages the execution of


the.NET code
 Manages the memory,
concurrency, security, ...

CLR

Common Language Runtime (CLR)

Operating System (OS)


.NET Framework Architecture (3)

Rich object-oriented library with


fundamental classes
Input-output, collections, text
processing, networking, security,
multi-threading, …

Base Class Library (BCL)


Common Language Runtime (CLR)

Operating System (OS)


.NET Framework Architecture (4)
Database access
ADO.NET, LINQ, LINQ-to-SQL and
Entity Framework
Strong XML support

ADO.NET, LINQ and XML (Data Tier)


Base Class Library (BCL)
Common Language Runtime (CLR)

Operating System (OS)


.NET Framework Architecture (5)
Windows Communication
Foundation (WCF) and Windows
Workflow Foundation (WWF) for
the SOA world

WCF and WWF (Communication and Workflow Tier)


ADO.NET, LINQ and XML (Data Tier)
Base Class Library (BCL)
Common Language Runtime (CLR)

Operating System (OS)


.NET Framework Architecture (6)
User interface technologies: Web based,
Windows GUI, WPF, Silverlight, mobile,

ASP.NET Windows
Web Forms, MVC, AJAX WPF Silverlight
Mobile Internet Toolkit Forms
WCF and WWF (Communication and Workflow Tier)
ADO.NET, LINQ and XML (Data Tier)
Base Class Library (BCL)
Common Language Runtime (CLR)

Operating System (OS)


.NET Framework Architecture (7)
Programming language on your flavor!

C# C++ VB.NET J# F# JScript Perl Delphi …


ASP.NET Windows
Web Forms, MVC, AJAX WPF Silverlight
Mobile Internet Toolkit Forms
WCF and WWF (Communication and Workflow Tier)
ADO.NET, LINQ and XML (Data Tier)
Base Class Library (BCL)
Common Language Runtime (CLR)

Operating System (OS)


.NET Framework 4.0

15
The Future

16
Common Language
Runtime (CLR)
The Heart of .NET Framework
Common Language Runtime (CLR)
 Managed execution environment

 Controls the execution of managed .NET


programming code
 Something like virtual machine

 Like the Java Virtual Machine (JVM)


 Not an interpreter

 Compilation on-demand is used


 Known as Just In Time (JIT) compilation
 Possible compilation in advance (Ngen)
Responsibilities of CLR
 Execution of the IL code and the JIT
compilation
 Managing memory and application resources

 Ensuring type safety

 Interaction with the OS

 Managing security

 Code access security


 Role-based security
Responsibilities of CLR (2)
 Managing exceptions

 Managing concurrency – controlling the

parallel execution of application threads


 Managing application domains and their

isolation
 Interaction with unmanaged code

 Supporting debug /

profile of .NET code


CLR Architecture
Base Class Library Support

Thread Support COM Marshaler

Type Checker Exception Manager

Security Engine Debug Engine

IL to Native Code Garbage


JIT Compiler Manager Collector

Class Loader
Managed and
Unmanaged Code
What is the Difference?
Managed Code
 CLR executed code is called managed code

 Represents programming code in the low level


language MSIL (MS Intermediate Language)
 Contains metadata

 Description of classes, interfaces, properties,


fields, methods, parameters, etc.
 Programs, written in any .NET language are

 Compiled to managed code (MSIL)


 Packaged as assemblies (.exe or .dll files)
Managed Code (2)
 Object-oriented

 Secure

 Reliable

 Protected from irregular use of types (type-safe)


 Allows integration between components and
data types of different programming
languages
 Portable between different platforms

 Windows, Linux, Max OS X, etc.


Unmanaged (Win32) Code
 No protection of memory and type-safety

 Reliability problems
 Safety problems
 Doesn’t contain metadata

 Needs additional overhead like (e.g. use COM)


 Compiled to machine-dependent code

 Need of different versions for different


platforms
 Hard to be ported to other platforms
Memory Management
 CLR manages memory automatically

 Dynamically loaded objects are stored in the


managed heap
 Unusable objects are automatically cleaned up
by the garbage collector
 Some of the big problems are solved

 Memory leaks
 Access to freed or unallocated memory
 Objects are accessed through a reference
Intermediate
Language (MSIL)
Intermediate Language
(MSIL, IL, CIL)
 Low level language (machine language) for the
.NET CLR
 Has independent set of CPU instructions

 Loading and storing data, calling methods


 Arithmetic and logical operations
 Exception handling
 Etc.
 MSIL is converted to instructions for the
current physical CPU by the JIT compiler
Sample MSIL Program

.method private hidebysig static void Main() cil managed


{
.entrypoint
// Code size 11 (0xb)
.maxstack 8
ldstr "Hello, world!"
call void
[mscorlib]System.Console::WriteLine(string)
ret
} // end of method HelloWorld::Main
Compilation and Execution
Assembly
Compilation (.EXE or
Code .DLL file)
Source Language
code compiler MSIL
Metadata
Metadata

When given
method is called
for the first time
Execution
Pre-compilation
Machine JIT during the
code compiler install (NGEN)
.NET Applications
Assemblies, Metadata and Applications
.NET Assemblies
 .NET assemblies:

 Self-containing .NET components


 Stored in .DLL and .EXE files
 Contain list of classes, types and resources
 Smallest deployment unit in CLR
 Have unique version number
 .NET deployment model

 No version conflicts (forget the "DLL hell")


 Supports side-by-side execution of different
versions of the same assembly
Metadata in the Assemblies
 Metadata in the .NET assemblies

 Data about data contained in the assembly


 Integral part of the assembly
 Generated by the .NET languages compiler
 Describes all classes, their class members,
versions, resources, etc.
Metadata in Assemblies
Type Description
Classes, interfaces, inner types, base
classes, implemented interfaces,
member fields, properties, methods,
method parameters, return value,
attributes, etc.

Assembly Description

Name
Name
Version [digital
[digital
Version
Localization signature]
signature]
Localization

Dependencies
Dependencies on
on other
other assemblies
assemblies
Security
Security permissions
permissions
Exported
Exported types
types
.NET Applications
 Configurable executable .NET units

 Consist of one or more assemblies

 Installed by "copy / paste"

 No complex registration of components


 Different applications use different versions of
common assemblies
 No conflicts due to their "strong name"
 Easy installation, un-installation and update
Common Type System (CTS)
 CTS defines the CLR supported types of
data and the operations over them
 Ensures data level compatibility between
different .NET languages
 E.g. string in C# is the same like String in
VB.NET and in J#
 Value types and reference types

 All types derive from System.Object


The .NET Languages
C#, VB.NET, C++, J#, etc.
.NET Languages
 .NET languages by Microsoft

 C#, VB.NET, Managed C++, J#, F#, JScript


 .NET languages by third parties

 Object Pascal, Perl, Python, COBOL, Haskell,


Oberon, Scheme, Smalltalk…
 Different languages can be mixed in a single
application
 Cross-language inheritance of types and
exception handling
C# Language
 C# is mixture between C++, Java and Delphi
 Fully object-oriented by design
 Component-oriented programming model
 Components, properties and events
 No header files like C/C++
 Suitable for GUI and Web applications
 XML based documentation
 In C# all data types are objects
 Example: 5.ToString() is a valid call
C# Language – Example
 C# is standardized by ECMA and ISO
 Example of C# program:
using System;

class NumbersFrom1to100
{
static void Main()
{
for (int i=1; i<=100; i++)
{
Console.WriteLine(i);
}
}
}
Framework Class
Library (FCL)
Standard Out-of-the-box .NET APIs
Framework Class Library (FCL)
 Framework Class Library is the standard
.NET Framework library of out-of-the-box
reusable classes and components (APIs)

ASP.NET Windows
Web Forms, MVC, AJAX WPF Silverlight
Mobile Internet Toolkit Forms

WCF and WWF (Communication and Workflow Tier)

ADO.NET, LINQ and XML (Data Tier)

Base Class Library (BCL)


FCL Namespaces

ASP.NET Windows WPF & Silverlight


Web Forms, MVC, AJAX Forms System.Windows
Mobile Internet Toolkit System.Windows
System.Windows
System.Windows
System.Web
System.Web .Forms
.Forms System.Windows.Media
System.Windows.Media

System.Web.Mvc
System.Web.Mvc System.Drawing
System.Drawing System.Windows.Markup
System.Windows.Markup

WCF and WWF (Communication and Workflow Tier)


System.ServiceModel
System.ServiceModel System.Activities
System.Activities System.Workflow
System.Workflow

ADO.NET, LINQ and XML (Data Tier)


System.Data
System.Data System.Linq
System.Linq System.Xml
System.Xml

System.Data.Linq
System.Data.Linq System.Xml.Linq
System.Xml.Linq System.Data.Entity
System.Data.Entity
Visual Studio IDE
Powerful Development Environment for .NET
Visual Studio
 Visual Studio is powerful Integrated
Development Environment (IDE) for .NET
Developers
 Create, edit, compile and run .NET applications
 Different languages – C#, C++, VB.NET, J#, …
 Flexible code editor
 Powerful debugger
 Integrated with SQL Server and IIS
 Strong support of Web services, WCF and WWF
Visual Studio (2)
 Visual programming

 Component-oriented, event based


 Managed and unmanaged code

 Helpful wizards and editors

 Windows Forms Designer


 WCF / Silverlight Designer
 ASP.NET Web Forms Designer
 ADO.NET / LINQ-to-SQL / XML Data Designer
 Many third party extensions
Visual Studio IDE
.NET Framework Overview

Questions?

http://aspnetcourse.telerik.com

You might also like