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

Event Driving Chapter - 2

Chapter 2 introduces the .NET Framework, highlighting its goals such as support for industry standards, extensibility, and improved security. It explains key components like the Common Language Runtime (CLR) and the Framework Base Class Library, which facilitate application development and deployment. The chapter also covers memory management improvements and the integration of various programming languages within the .NET ecosystem.

Uploaded by

Dawit Sebhat
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)
26 views23 pages

Event Driving Chapter - 2

Chapter 2 introduces the .NET Framework, highlighting its goals such as support for industry standards, extensibility, and improved security. It explains key components like the Common Language Runtime (CLR) and the Framework Base Class Library, which facilitate application development and deployment. The chapter also covers memory management improvements and the integration of various programming languages within the .NET ecosystem.

Uploaded by

Dawit Sebhat
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
You are on page 1/ 23

CHAPTER 2

INTRODUCTION TO .NET

03/12/2022 Compiled By Deresse Demeke 1


INTRODUCTION TO .NET
➢ The .NET Framework is a collection of fundamental classes designed to
provide the common services needed to run applications.
Goals of the .NET Framework
Microsoft designed the .NET Framework with certain goals in mind.
1. Support of Industry Standards
2. Extensibility
3. Unified Programming Models
4. Easier Deployment
5. Improved Memory Management
6. Improved Security Model
03/12/2022 Compiled By Deresse Demeke 2
Support of Industry Standards
➢ Microsoft wanted the .NET Framework to be based on industry standards and practices. As a result,
the framework relies heavily on industry standards such as the Extensible Markup Language (XML),
HTML 5, and OData.

➢ Microsoft has also submitted a Common Language Infrastructure (CLI) Working Document to the
European Computer Manufacturers Association (ECMA), which oversees many of the common
standards in the computer industry.

➢The CLI is a set of specifications needed to create compilers that conform to the .NET Framework.

➢Third-party vendors can also create a CLR that will allow .NET-compliant languages to run on
different platforms. One example, Mono is an open source, cross platform implementation of the
CLR that gives C# applications the ability to run on the Linux platform.
03/12/2022 Compiled By Deresse Demeke 3
Extensibility
➢ To create a highly productive environment in which to program, Microsoft realized
the .NET Framework had to be extensible.

➢ As a result, Microsoft exposed the framework class hierarchy to developers.

➢Through inheritance and interfaces, you can easily access and extend the functionality
of these classes.

➢For example, you could create a button control class that not only inherits its base
functionality from the button class exposed by the .NET Framework, but also extends
the base functionality in the unique way required by your application.
03/12/2022 Compiled By Deresse Demeke 4
Unified Programming Models
➢ Another important goal Microsoft incorporated into the .NET Framework was cross-language
independence and integration.

➢ To achieve this goal, all languages that support the Common Language Specification (CLS) compile
into the same intermediate language, support the same set of basic data types, and expose the same
set of code accessibility methods.

➢ As a result, not only can classes developed in the different CLS-compliant languages communicate
seamlessly with one another, but you can also implement OOP constructs across languages.

➢ For example, you could develop a class written in C# that inherits from a class written using Visual
Basic (VB).
03/12/2022 Compiled By Deresse Demeke 5
Easier Deployment
➢ Microsoft needed a way to simplify application deployment.

➢Before the development of the .NET Framework, when components were deployed, component information had
to be recorded in the system registry.

➢ Many of these components, especially system components, were used by several different client applications. When
a client application made a call to the component, the registry was searched to determine the metadata needed to
work with the component.

➢ If a newer version of the component was deployed, it replaced the registry information of the old component.
Often, the new components were incompatible with the old version and caused existing clients to fail.

➢ The .NET Framework combats this problem by storing the metadata for working with the component in a file
called a manifest, which is packaged in the assembly containing the component code.

03/12/2022 Compiled By Deresse Demeke 6


➢An assembly is a package containing the code, resources, and metadata needed to run an application.

➢By default, an assembly is marked as private and placed in the same directory as the client assembly.

➢This ensures that the component assembly is not inadvertently replaced or modified and also allows for a
simpler deployment because there is no need to work with the registry.

➢If a component needs to be shared, its assembly is deployed to a special directory referred to as the Global
Assembly Cache (GAC).

➢The manifest of the assembly contains versioning information, so newer versions of the component can be
deployed side by side with the older versions in the GAC.

➢By default, client assemblies continue to request and use the versions of the components they were intended to
use.

➢ Older client assemblies will no longer fail when


03/12/2022 newer
Compiled versions
By Deresse Demeke of the component are installed. 7
Improved Memory Management
➢ A common problem of programs developed for the Windows platform has been
memory management. Often, these programs have caused memory leaks.
➢ A memory leak occurs when a program allocates memory from the operating system
but fails to release the memory after it is finished working with the memory.
➢ This memory is no longer available for other applications or the operating system,
causing the computer to run slowly or even to stop responding.
➢ This problem is compounded when the program is intended to run for a long time,
such as a service that runs in the background.
➢ To combat this problem, the .NET Framework uses nondeterministic finalization.
Instead of relying on the applications to deallocate the unused memory, the framework
uses a garbage collection object.
➢The garbage collector periodically scans for unused memory blocks and returns them
to the operating system.
03/12/2022 Compiled By Deresse Demeke 8
Improved Security Model
➢In an effort to make security easier to implement and more robust, the .NET Framework uses
the concept of code identity and code access.

➢When an assembly is created, it is given a unique identity. When a server assembly is created,
you can grant access permissions and rights.

➢ When a client assembly calls a server assembly, the runtime will check the permissions and
rights of the client, and then grant or deny access to the server code accordingly. Because each
assembly has an identity, you can also restrict access to the assembly through the operating
system.
03/12/2022 Compiled By Deresse Demeke 9
Components of the .NET Framework
1. Common Language Runtime
2. Framework Base Class Library
3. Data Classes
4. Windows Applications
5. Web Applications
6. Windows Store Applications
7. Application Services

03/12/2022 Compiled By Deresse Demeke 10


Common Language Runtime
➢ The fundamental component of the .NET Framework is the CLR.

➢The CLR manages the code being executed and provides for a layer of abstraction between the code and the
operating system.

Built into the CLR are mechanisms for the following:

➢ loading code into memory and preparing it for execution

➢ converting the code from the intermediate language to native code

➢managing code execution

➢ managing code and user-level security

➢ automating deallocation and release of memory

➢debugging and tracing code execution and providing structured exception handling
03/12/2022 Compiled By Deresse Demeke 11
.NET Framework and CLR Execution Model

03/12/2022 Compiled By Deresse Demeke 12


Framework Base Class Library
➢ Built on top of the CLR is the .NET Framework base class library.

➢Included in this class library are reference types and value types that encapsulate access to the
system functionality.

➢Types are data structures.

➢ A reference type is a complex type for example, classes and interfaces.

➢A value type is simple type for example, integer or Boolean.

➢The base class library includes types that encapsulate data structures, perform basic
input/output operations, invoke security management, manage network communication, and
perform many other functions.
03/12/2022 Compiled By Deresse Demeke 13
Data Classes
➢ Built on top of the base classes are classes that support data management.

➢This set of classes is commonly referred to as ADO.NET. Using the ADO.NET object model,
programmers can access and manage data stored in a variety of data storage structures through
managed providers.

➢Microsoft has written and tuned the ADO.NET classes and object model to work efficiently in
a loosely coupled, disconnected, multitiered environment.

➢ADO.NET not only exposes the data from the database, but also exposes the metadata
associated with the data.

➢ Data is exposed as a sort of mini-relational database.


03/12/2022 Compiled By Deresse Demeke 14
Windows Applications
➢ With the .NET Framework, Microsoft has incorporated a set of base classes exposing advanced

Windows GUI functionality equally among the .NET-compliant languages.

➢ This has allowed Windows GUI development to become consistent across the various .NET-enabled

programming languages, combining the ease of development with the full features of the API.

➢The .NET Framework includes a set of classes collectively referred to as the Windows Presentation

Foundation (WPF).

➢WPF integrates a rendering engine that is built to take advantage of modern graphics hardware and

feature rich operating systems likeWindows 10.


03/12/2022 Compiled By Deresse Demeke 15
Web Applications
➢ The .NET Framework exposes a base set of classes that can be used on a web server to create
user interfaces and services exposed to web-enabled clients. These classes are collectively
referred to as ASP.NET.

➢Using ASP.NET, you can develop one user interface that can dynamically respond to the type
of client device making the request.

➢ At runtime, the .NET Framework takes care of discovering the type of client making the
request (browser type and version) and exposing an appropriate interface.

➢Another improvement in web application development using the .NET Framework is that
server-side code can be written in any .NET-compliant language.
03/12/2022 Compiled By Deresse Demeke 16
Windows Store Applications
➢ A new type of Windows application is available for the Windows 8 operating system:
the Windows Store app.

➢Windows Store apps are intended for devices such as tablets and phones that take
advantage of touch screens for user input, and continuous Internet connectivity. There
are two options for building Windows Store apps.

➢You can use one of the .NET languages (C#/VB/C++) in combination with XAML
or you can use JavaScript in combination with HTML5.

03/12/2022 Compiled By Deresse Demeke 17


Compiling and Executing Managed Code
➢ When .NET code is compiled, it is converted into a .NET portable executable (PE) file.

➢ The compiler translates the source code into Microsoft intermediate language (MSIL) format.

➢ MSIL is CPU-independent code, which means it needs to be further converted into CPU-specific native code before
executing.

➢ Along with the MSIL code, the PE file includes the metadata information contained within the manifest.

➢ The incorporation of the metadata in the PE file makes the code self-describing.

➢ Because the source code for the various .NET-compliant languages is compiled into the same MSIL and metadata format
based on a common type system, the .NET platform supports language integration.

➢ For example, client code written in VB could instantiate and use the methods of a component written in C++.

03/12/2022 Compiled By Deresse Demeke 18


Contd…
➢ With .NET language integration, you could write a .NET class in VB that inherits from a class written in C#, and then overrides some
of its methods.

➢ Before the MSIL code in the PE file is executed, a .NET Framework just-in-time (JIT) compiler converts it into CPU-specific native
code.

➢ To improve efficiency, the JIT compiler does not convert all the MSIL code into native code at the same time.

➢ MSIL code is converted on an as-needed basis. When a method is executed, the compiler checks to see if the code has already been
converted and placed in cache. If it has, the compiled version is used; otherwise, the MSIL code is converted and stored in the cache for
future calls.

➢ Because JIT compilers are written to target different CPUs and operating systems, developers are freed from needing to rewrite their
applications to target various platforms.

➢ It is conceivable that the programs you write for a Windows server platform will also run on a UNIX server. All that is needed is a JIT
compiler for the UNIX architecture.
03/12/2022 Compiled By Deresse Demeke 19
Using the Visual Studio Integrated Development
Environment
➢You can write C# code using a simple text editor and compile it with a command-line
compiler.

➢You will find, however, that programming enterprise-level applications using a text editor
can be frustrating and inefficient.

➢ Most programmers who code for a living find an integrated development environment
(IDE) invaluable in terms of ease of use and increased productivity.

➢ Microsoft has developed an exceptional IDE in Visual Studio (VS). Integrated into VS are
many features that make programming for the .NET Framework more intuitive, easier, and
more productive.
03/12/2022 Compiled By Deresse Demeke 20
Some of Visual Studio’s useful features are:
➢ Editor features such as automatic syntax checking, autocomplete, and color highlighting one IDE for all
.NET languages extensive debugging support, including the ability to set breakpoints, step through code,
and view and modify variables

➢ drag-and-drop GUI development

➢ XML and HTML editing

➢ automated deployment tools that integrate with Windows Installer the ability to view and manage servers
from within the IDE

➢ a fully customizable and extensible interface

03/12/2022 Compiled By Deresse Demeke 21


Hello, World
Remove the using declaration and add the System
The using declaration is there to reduce the namespace to the Console class with the
code with opening a namespace. invocation of the WriteLine method
1. using static System.Console; 1. class Program
2. class Program 2. {
3. { 3. static void Main()
4. static void Main() 4. {
5. { 5. System.Console.WriteLine("Hello,
6. WriteLine("Hello, World!"); World!");
7. } 6. }
8. } 7. }

03/12/2022 Compiled By Deresse Demeke 22


Compiling with .NET
➢You can compile this program by simply running the C# command-line compiler (csc.exe)
against the source file, like this:
csc HelloWorld.cs
➢ If you want to compile code from the command line using the csc command, you should be
aware that the .NET command-line tools, including csc, are available only if certain
environment variables have been set up.
➢ Depending on how you installed .NET (and Visual Studio), this may or may not be the case
on your machine.
➢Compiling the code produces an executable file named HelloWorld.exe, which you can run
from the command line.
03/12/2022 Compiled By Deresse Demeke 23

You might also like