0% found this document useful (0 votes)
12 views23 pages

DotNet Framework - Intro Session

.NET Framework is a versatile software platform for building applications across various operating systems, including Windows, macOS, and Linux. It features interoperability, support for multiple programming languages, and a common runtime engine, along with a comprehensive base class library. Key components include the Common Language Runtime (CLR), Common Type System (CTS), and Common Language Specification (CLS), which facilitate the development and execution of managed code.

Uploaded by

kaleabresom89
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views23 pages

DotNet Framework - Intro Session

.NET Framework is a versatile software platform for building applications across various operating systems, including Windows, macOS, and Linux. It features interoperability, support for multiple programming languages, and a common runtime engine, along with a comprehensive base class library. Key components include the Common Language Runtime (CLR), Common Type System (CTS), and Common Language Specification (CLS), which facilitate the development and execution of managed code.

Uploaded by

kaleabresom89
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter One

Introducing the .NET


Framework
2023@[Link]’sUniversity

1
Introduction to .NET Platform
• .NET Framework is a software platform for building systems on the
Windows family of operating systems, as well as on numerous
non-Microsoft operating systems such as macOS, iOS, Android, and
various Unix/Linux distributions.
• The interoperability among different platforms becomes easy with the
introduction of .NET core in 2016 by Microsoft.

2
Features Provided Courtesy of .NET:
✔ Interoperability with existing code:
✔ Support for numerous programming languages:
• .NET applications can be created using any number of programming languages (C#, Visual Basic, F#, and
so on).
✔ A common runtime engine shared by all .NET-aware languages:
✔ Language integration:
▪ .NET supports cross-language inheritance, cross-language exception handling, and cross-language
debugging of code. For example, you can define a base class in C# and extend this type in
Visual Basic.
✔ A comprehensive base class library:
• This library provides thousands of predefined types that allow you to build
code libraries
✔ A simplified deployment model:

3
The Building Blocks of the .NET
Platform (the CLR(.NET Runtime),
CTS, and CLS)

4
Common Language Runtime(CLR).
• From a programmer’s point of view, .NET can be understood as a
runtime environment and a comprehensive base class library.
• The runtime layer is properly referred to as the Common Language
Runtime(CLR) or .NET Runtime.
• Contains set of minimal implementations that are tied specifically to a
platform (Windows, iOS, Linux) and architecture (x86, x64, ARM) as
well as all of base types for .NET.
• The primary role of the CLR is to locate, load, and manage .NET objects on
your behalf. The CLR also takes care of a number of low-level details such as
memory management, application hosting, coordinating threads, and
performing basic security checks (among other low-level details).

5
Common Type System (CTS)
• Another building block of the .NET platform is the Common Type
System, or CTS. The CTS specification fully describes all possible data
types and all programming constructs supported by the runtime,
• It specifies how these entities can interact with each other, and details how
they are represented in the .NET metadata format.

6
Common Language Specification (CLS)
• Different languages express the same programming constructs in
unique, language-specific terms.
• For example, in C# you denote string concatenation using the plus
operator (+), while in VB you typically make use of the ampersand (&).
• The CLS is a set of rules that describe in bright detail the minimal and
complete set of features a given .NET-aware compiler must support to
produce code that can be hosted by the CLR, while at the same time
be accessed in a uniform manner by all languages that target the .NET
platform. In many ways, the CLS can be viewed as a subset of the full
functionality defined by the CTS.

7
The Role of the Base Class Libraries
• In addition to the CLR, CTS, and CLS specifications, the .NET platform
provides a base class library that is available to all .NET programming
languages.
• Not only does this base class library encapsulate various primitives
such as threads, file input/output (I/O), graphical rendering systems,
and interaction with various external hardware devices, but it also
provides support for a number of services required by most
real-world applications.

8
The Role of the Base Class Libraries(Con’t)

Figure 1 . The CLR, CTS, CLS, and base class library


relationship
9
What C# Brings to the Table
• C# is a programming language whose core syntax looks
very similar to the syntax of Java.
• However, calling C# a Java clone is inaccurate. In reality, both C#
and Java are members of the C family of programming
languages (e.g., C, Objective C, C++) and, therefore, share a
similar syntax.
• The truth of the matter is that many of C#’s syntactic
constructs are modeled after various aspects of Visual
Basic (VB) and C++. For example, like VB, C# supports the
notion of class properties (as opposed to traditional getter
and setter methods) and optional parameters.
• Like C++, C# allows you to overload operators, as well as
create structures, enumerations, and callback functions
(via delegates).
10
C# features
• No pointers required! C# programs typically have no need for direct pointer.
• Automatic memory management through garbage collection. Given this, C# does
not support a delete keyword.
• Formal syntactic constructs for classes, interfaces, structures, enumerations, and
delegates.
• The C++-like ability to overload operators for a custom type, without the
complexity (e.g., making sure to “return *this to allow chaining” is not your
problem).
• Support for attribute-based programming. This brand of development allows you
to annotate types and their members to further qualify their behavior. For
example, if you mark a method with the [Obsolete] attribute, programmers will
see your custom warning message print out if they attempt to make use of the
decorated member.

11
Managed vs. Unmanaged Code
• It is important to note that the C# language can be used only to build software that is hosted under the
.NET runtime (you could never use C# to build a native COM server or an unmanaged C/C++-style
application). Officially speaking, the term used to describe the code targeting the .NET runtime is managed
code.
• The binary unit that contains the managed code is termed an assembly.
• Conversely, code that cannot be directly hosted by the .NET runtime is termed unmanaged code.
• The .NET platform can run on a variety of operating systems.
• Thus, it is quite possible to build a C# application on a Windows machine using Visual Studio and run the program
on a macOS machine using the .NET Core runtime.
• As well, you could build a C# application on Linux using Xamarin Studio and run the program on Windows, macOS
and so on.
• With the most recent release of Visual Studio 2017, you can also build .NET Core applications on a Mac to be run on
Windows, macOS or Linux.
• To be sure, the notion of a managed environment makes it possible to build, deploy, and run .NET programs on a
wide variety of target machines.

12
An Overview of .NET Assemblies
• Regardless of which .NET language you choose to program with, understand that despite .NET
binaries taking the same file extension as unmanaged Windows binaries (*.dll or *.exe), they have
absolutely no internal similarities.
• Specifically, .NET binaries do not contain platform-specific instructions but rather
platform-agnostic Intermediate Language (IL) and type metadata.

Note IL is also known as


Microsoft Intermediate Language
(MSIL) or alternatively as the
Common Intermediate Language
(CIL).
Thus, as you read the .NET
literature, understand that IL,
MSIL, and CIL are all describing
essentially the same concept.
13
.NET Assemblies …
• When a *.dll or *.exe has been created using a .NET-aware compiler, the
binary blob is termed an assembly.
• An assembly contains CIL code, which is conceptually similar to Java
bytecode in that it is not compiled to platform-specific instructions until
absolutely necessary.
• In addition to CIL instructions, assemblies also contain metadata that
describes in vivid detail the characteristics of every “type” within the binary.
• For example, if you have a class named Employee, the type metadata describes
details such as Employee’s base class, specifies which interfaces are implemented by
Employee (if any), and gives full descriptions of each member supported by the
Employee type.
• .NET metadata is always present within an assembly and is automatically
generated by a .NET-aware language compiler.

14
The Role of the Common Intermediate Language
• Let’s examine CIL code, type metadata, and the assembly manifest in a bit more
detail.
• CIL is a language that sits above any particular platform-specific instruction set.
For example, the following C# code models a trivial calculator. Don’t concern
yourself with the exact syntax for now, but do notice the format of the Add()
method in the Calc class. After you compile this code file using the
C# compiler ([Link]), you end up with a
single-file *.exe assembly that contains a
manifest, CIL instructions, and metadata
describing each aspect of the Calc and
Program classes.

15
The Role of the Common Intermediate
Language(Con’t)
• Now, recall that this is true of all .NET-aware compilers. To illustrate, assume you
created this same application using Visual Basic, rather than C#.

16
Benefits of CIL
At this point, you might be wondering exactly what is gained
by compiling source code into CIL rather than directly to a
specific instruction set. One benefit is language integration.
As you have already seen, each .NET-aware compiler
produces nearly identical CIL instructions. Therefore, all
languages are able to interact within a well-defined binary
arena.
Furthermore, given that CIL is platform-agnostic, the .NET
Framework itself is platform-agnostic, providing the same
benefits Java developers have grown accustomed to (e.g., a
single codebase running on numerous operating systems). In
fact, there is an international standard for the C# language,
and a large subset of the .NET platform and implementations
already exists for many non-Windows operating systems
(more details at the conclusion of this chapter).

17
Compiling CIL to Platform-Specific
Instructions
• Because assemblies contain CIL instructions rather than platform-specific instructions, CIL code
must be compiled on the fly before use.
• The entity that compiles CIL code into meaningful CPU instructions is a JIT(Just In Time) compiler,
which sometimes goes by the friendly name of jitter.
• The .NET runtime environment leverages a JIT compiler for each CPU targeting the runtime, each
optimized for the underlying platform.
• For example,
❖ if you are building a .NET application to be deployed to a handheld device (such as a Windows Phone
device), the corresponding jitter is well equipped to run within a low-memory environment.
❖ On the other hand, if you are deploying your assembly to a back-end company server (where memory is
seldom an issue), the jitter will be optimized to function in a high-memory environment.
• In this way, developers can write a single body of code that can be efficiently JIT compiled and
executed on machines with different architectures.

18
The Role of .NET Type Metadata
• In addition to CIL instructions, a .NET assembly
contains full, complete, and accurate metadata,
❖ Which describes every type (e.g., class, structure,
enumeration) defined in the binary, as well as the members
of each type (e.g., properties, methods, events).
❖ Thankfully, it is always the job of the compiler (not the
programmer) to emit the latest and greatest type
metadata.

19
• To illustrate the format of .NET type metadata, let’s take a look at the
metadata that has been generated for the Add() method of the C# Calc class
you examined previously (the metadata generated for the Visual Basic version
of the Add() method is similar; .

20
The Role of the Assembly Manifest
• Last but not least, remember that a .NET assembly also contains
metadata that describes the assembly itself (technically termed a
manifest).
• Among other details, the manifest documents all external assemblies
required by the current assembly to function correctly, the assembly’s
version number, copyright information, and so forth.
• Like type metadata, it is always the job of the compiler to generate
the assembly’s manifest.

21
• Here are some relevant details of the manifest generated when
compiling the [Link] code file shown earlier in this chapter
(assume you instructed the compiler to name your assembly
[Link]):

22
• The following Figure illustrates the high-level workflow that takes place
between your source code (which is making use of base class library
types), a given .NET compiler, and the .NET execution engine.

23

You might also like