0% found this document useful (0 votes)
10 views

UNIT-I Dotnet (2018)

Doy Net Study Material

Uploaded by

sayeedabegum2010
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

UNIT-I Dotnet (2018)

Doy Net Study Material

Uploaded by

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

UNIT – I

INTRODUCTION:

What is .NET Framework?


It is a new, easy, and extensive programming platform. It is not a programming language, but it
supports several programming languages. By default .NET comes with few programming
languages including C# (C Sharp), VB.NET, J# and managed C++. It is a common platform for
all the supported languages. It gives a common class library, which can be called from any of the
supported languages. So, developers need not learn many libraries when they switch to a
different language. Only the syntax is different for each language. When we write code in any
language and compile, it will be converted to an 'Intermediate Language' (Microsoft Intermediate
Language - MSIL). So, our compiled executable contains the IL and not really executable
machine language. When the .NET application runs, the .NET framework in the target computer
take care of the execution. (To run a .NET application, the target computer should have .NET
framework installed.) The .NET framework converts the calls to .NET class libraries to the
corresponding APIs of the Operating system. Whether we write code in C# or VB.NET, you are
calling methods in the same .NET class libraries. The same .NET framework executes the C#
and VB.NET applications. So, there won't be any performance difference based on the language
you write code. The .NET Framework is an integral Windows component that supports building
and running the next generation of applications and XML Web services. The .NET Framework is
designed to fulfill the following objectives:
 To provide a consistent object-oriented programming environment whether object code is
stored and executed locally, executed locally but Internet-distributed, or executed
remotely.
 To provide a code-execution environment that minimizes software deployment and
versioning conflicts.
 To provide a code-execution environment that promotes safe execution of code, including
code created by an unknown or semi-trusted third party.
 To provide a code-execution environment that eliminates the performance problems of
scripted or interpreted environments.
 To make the developer experience consistency across widely varying types of
applications, such as Windows-based applications and Web-based applications.
 To build all communication on industry standards to ensure that code based on the .NET
Framework can integrate with any other code.

The .NET Framework has two main components: the common language runtime and the .NET
Framework class library. The common language runtime is the foundation of the .NET
Framework. You can think of the runtime as an agent that manages code at execution time,
providing core services such as memory management, thread management, and remoting, while
also enforcing strict type safety and other forms of code accuracy that promote security and
robustness. In fact, the concept of code management is a fundamental principle of the runtime.
Code that targets the runtime is known as managed code, while code that does not target the
runtime is known as unmanaged code. The class library, the other main component of the .NET
Framework, is a comprehensive, object-oriented collection of reusable types that you can use to
develop applications ranging from traditional command-line or graphical user interface (GUI)
applications to applications based on the latest innovations provided by ASP.NET, such as Web
Forms and XML Web services. The .NET Framework can be hosted by unmanaged components
that load the common language runtime into their processes and initiate the execution of
managed code, thereby creating a software environment that can exploit both managed and
unmanaged features. The .NET Framework not only provides several runtime hosts, but also
supports the development of third-party runtime hosts.

What is Microsoft .Net Framework?

The .Net framework is a software development platform developed by Microsoft. The


framework was meant to create applications, which would run on the Windows Platform. The
first version of the .Net framework was released in the year 2002.

The version was called .Net framework 1.0. The .Net framework has come a long way since
then, and the current version is 4.7.1.

The .Net framework can be used to create both - Form-based and Web-based applications. Web
services can also be developed using the .Net framework.

The framework also supports various programming languages such as Visual Basic and C#. So
developers can choose and select the language to develop the required application. In this
chapter, you will learn some basics of the .Net framework.

.Net Framework Version History

The first version of the .Net framework was released in the year 2002. The version was called
.Net framework 1.0. The .Net framework has come a long way since then, and the current
version is 4.7.1.

Below is the table of .Net framework versions, which have been released with their release dates.
Every version has relevant changes to the framework.

For example, in framework 3.5 and onwards a key framework called the Entity framework was
released. This framework is used to change the approach in which the applications are developed
while working with databases.

Version number CLR version Release date

1.0 1.0 2002-02-13

1.1 1.1 2003-04-24

2.0 2.0 2005-11-07


3.0 2.0 2006-11-06

3.5 2.0 2007-11-19

4.0 4 2010-04-12

4.5 4 2012-08-15

4.5.1 4 2013-10-17

4.5.2 4 2014-05-05

4.6 4 2015-07-20

4.6.1 4 2015-11-17

4.6.2 4 2016-08-02

4.7 4 2017-04-05

4.7.1 4 2017-10-17

The biggest advantage of the .Net framework is that it supports Windows platform. Almost
everyone works with Windows machines.

Microsoft always ensures that .Net frameworks are in compliance with all the supported
Windows operating systems.

DOT NET FRAMEWORK FEATURES:


 Multi language:.NET platform supports number of languages such as C++, C#, JScript
and VisualBasic.NET.
 Hardware independent: All the programs in the .NET platform are compiled into a
binary code called MSIL (Microsoft Intermediate Language). This code is independent
of hardware and operating system.
 Applications are portable:.NET compiler creates a platform independent binary code
called Portable Executables (PEs). These PEs can be implemented in all types of
hardware architecture.
 Common Language Specification: It is a list of agreements in the .NET platform. Any
language in the .NET platform must satisfy the requirements of CLS.
 Common Language Runtime: The execution of .NET application is managed by a
special execution engine called Common Language Runtime (CLR).
 Assemblies: Defines the concept of assemblies, which are collections of types and
resources that form logical units of functionality. Assemblies are the fundamental units of
deployment, version control, reuse, activation scoping, and security permissions.
 Application Domains: Explains how to use application domains to provide isolation
between applications.
 Runtime Hosts: Describes the runtime hosts supported by the .NET Framework,
including ASP.NET, Internet Explorer, and shell executables.
 Common Type System: Identifies the types supported by the common language runtime.
Common Type System (CTS) specifies the rules related to data types that languages must
follow. As programs written in all languages are ultimately converted to MSIL, data
types in all languages must be convertible to certain standard data types.CTS is a part of
cross-language integration, which allows classes written in one language to be used and
extended by another language.
 Metadata and Self-Describing Components: Explains how the .NET Framework
simplifies component interoperation by allowing compilers to emit additional declarative
information, or metadata, into all modules and assemblies.
 Cross-Language Interoperability: Explains how managed objects created in different
programming languages can interact with one another.
 .NET Framework Security: Describes mechanisms for protecting resources and code
from unauthorized code and unauthorized users.
 Unified Programming classes: These are predefined class libraries available in the .NET
framework which can be used by all programming languages of .NET framework.
 ASP.NET: It is a part of .NET framework. This contains number of controls and classes
to build simple web applications.
 Namespaces: It is a collection of different classes. .NET applications can be developed
using the classes in the System namespace.
 Cross-language Interoperability: .NET provides support for language interoperability.
However, it doesn„t mean every program written in a language can be used by another
language. To enable a program to be used with other languages, it must be created by
following a set of rules called Cross Language Specifications (CLS).Cross-language
inheritance is the ability to create a class in C# from a class created in VB.NET. When an
exception is raised by a program written in C#, the exception can be handled by VB.NET.
This kind of exception handling is called cross-language exception handling.
 Assemblies: An assembly is either a .DLL or .EXE that forms a part of an application. It
contains MSIL code that is executed by CLR. The following are other important points
related to an assembly:

It is the unit on which permissions are granted.Every assembly contains a version.


Assemblies contain interfaces and classes. They may also contain other resources such as
bitmaps, file etc. Every assembly

Assemblies may be either private, which are used only by the application to which they
belong or Global assemblies, which are used by any application in the system.Two
assemblies of the same name but with different versions can run side-by-side allowing
applications that depend on a specific version to use assembly of that version. The four
parts of an assembly are: Assembly Manifest - Contains name, version, culture, and
information about referenced assemblies. Type metadata - Contains information about
types defined in the assembly. MSIL – MSIL code. Resources - Files such as BMP or
JPG file or any other files required by application. Note: Assembly that contains only
resources is called as Satellite assembly. The following are different types of applications
that can be developed in .NET:
 Windows applications – typical Client/Server applications.

 Web applications – Web sites and Intranet applications.

 Web services – Programs that are accessible from anywhere using universal protocols
like HTTP and SOAP.

 Console Applications – Simple console based applications without any GUI. Run from
command prompt. Best suited to learn fundamentals and also for applications such as
server sockets.

 Mobile Applications – Contain web pages that run in mobile devices such as PDAs
(Personal Digital Assistant) and Cell phones.

Though .NET supports many languages, but the two languages will dominate programming in
.NET: VB.NET and C#. VB.NET is the successor to VB 6.0, but language wise, it was modified
substantially as it became complete OOPL – no more "object-based language." C# resembles
Java. Though Microsoft claims, C# resembles C++, but it resembles Java more than C++.
NOTE: The Common Language Runtime, Unified Programming classes and ASP.NET are
considered as the three major parts of .NET framework.

ARCHITECTURE AND COMPONENTS OF .NET FRAMEWORK 4.5


.NET framework is an integrated component of Windows operating system that supports the
development and execution of next-generation applications, Windows store apps and services.
.NET Framework 4.5 at its core consists of Common Language Runtime (CLR), Dynamic
Language Runtime (DLR), Base Class Library (BCL), Portable Class Library, Parallel Extension
and WinRT.
With .Net Framework 4.0 there are various new additions in BCL which includes DLR, MEF,
Parallel Extension, Entity Framework, WCF Data Services and ability to host .NET 4 runtime
with .NET 3.5, 3.0, 2.0 runtimes side by side under the same hosting process.

COMPONENTS OF .NET FRAMEWORK 4.5 ARCHITECTURE

1. Common Language Runtime: This acts as the execution engine for the .NET
Framework. All .NET programs executes under the supervision of CLR.
2. Base Class Library: This is a library of functionalities which are available to all
languages using the .NET Framework. It consists of classes, interfaces of reusable types
that integrates with CLR
3. Portable Class Library: The Portable Class Library project in Visual Studio 2012 allows
you to develop and build managed assemblies that work on multiple .NET Framework
platforms. Using a Portable Class Library project, you choose the platforms (such as
Windows Phone and .NET for Windows Store apps) to target.
4. Managed Extensibility Framework (MEF): MEF is a library for creating lightweight,
extensible applications. It allows application developers to discover and use extensions
with no configuration required.
5. Dynamic Language Runtime: This provides the runtime environment for dynamic
languages like python etc. for executing under the full control of CLR.
6. WinRT: WinRT or Windows Runtime APIs provides the user interface elements for
building Windows Store apps, and provides access to Windows 8 or Windows RT OS
features. WinRT supports development in C and other managed languages C# and
VB.NET, as well as JavaScript and TypeScript.

7. ASP.NET: This is used to build rich internet based web application.


8. Windows Store Apps (Metro Style Apps): A Windows Store app is a new type of
application that runs on Windows 8 devices and can take advantage of new WinRT APIs.
These can only be distributed in the Windows 8 store.
9. Desktop Apps (Windows Forms): A Windows Desktop app is traditional Windows Forms
application with a new name. Software developed for Windows XP, Windows Vista and
Windows 7 will be categorized as a Windows Desktop app when running in Windows 8.
Examples of Windows Desktop apps are Microsoft Office families products, notepad etc.
10. WPF(Window Presentation Foundation): WPF is used to create applications with a rich
user experience. It includes application UI, 2D graphics, 3D graphics and multimedia. It
takes advantage of hardware acceleration of modern graphic cards. WPF makes the UI
faster, scalable and resolution independent.
11. Silver Light: This is a cross-browser web based technology which allows designers and
developers to deliver Rich Internet Applications (RIA) embedded in Web pages.
12. Ado.Net: This is used to create Data Access Layer to query and manipulate data from
underlying data source like SQL Server, Oracle, and DB2 etc.
13. LINQ: This allows you to query the data from the various data sources (like SQL databases,
XML documents, Ado.Net Datasets, Various Web services and any other objects such as
Collections, Generics etc.) using a SQL Query like syntax with .Net framework languages
like C# and VB.
14. Ado.Net Entity Framework: This is used to query and store data into to the relational
databases (like SQL Server, Oracle, DB2 etc.) in ORM fashion.
15. Parallel Extension: This allows you to distribute your work code across multiple
processors to take advantage of the hardware.
16. WCF(Windows communication Foundation): It is a framework for building service-
oriented applications. Using WCF, you can send data as asynchronous messages from one
service endpoint to another.
17. Asp.Net WebAPI: Asp.Net Web API is a framework for building HTTP services that can be
consume by a broad range of clients including browsers, mobiles, iphone and tablets.
18. SignalR: ASP.NET SignalR is a library that simplifies the process of adding real-time web
functionality to applications. Real-time web functionality is the ability to have server code
push content to connected clients instantly as it becomes available, rather than having the
server wait for a client to request new data.
19. WF(Workflow Foundation): Windows Workflow Foundation (WF) is a Microsoft
technology that provides an API, an in-process workflow engine, and a rehostable designer
to implement long-running processes as workflows within .NET applications. It is used to
build process oriented business workflow and rules engine.
20. Visual Studio 2012: The Visual Studio IDE offers a set of tools that help you to write and
modify the code for your programs, and also detect and correct errors in your programs.
Using Visual Studio 2012 you can build Windows Store apps, desktop apps, mobile apps,
ASP.NET web apps, and web services.

JIT COMPILER
JIT (Just-in-Time):Just - in - Time (JIT) compiler, which compiles MSIL into native code that
is specific to the OS and machine architecture being targeted. Only at this point can the OS
execute the application. The just - in - time part of the name reflects the fact that MSIL code is
only compiled as, and when, it is needed. In the past, it was often necessary to compile your code
into several applications, each of which targeted a specific operating system and CPU
architecture. Often, this was a form of optimization. This is now unnecessary, because JIT
compilers (as their name suggests) use MSIL code, which is independent of the machine,
operating system, and CPU. Several JIT compilers exist, each targeting a different architecture,
and the appropriate one will be used to create the native code required.
JIT are of three types:
1. Pre JIT
2. Econo JIT
3. Normal JIT

Pre JIT: It converts all the code in executable code and it is slow
Econo JIT: It will convert the called executable code only. But it will convert code every time
when a code is called again.
Normal JIT: It will only convert the called code and will store in cache so that it will not require
converting code again. Normal JIT is fast.

1. Normal JIT

This complies only those methods that are called at runtime. These methods are compiled
only first time when they are called, and then they are stored in memory cache. This
memory cache is commonly called as JITTED. When the same methods are called again,
the complied code from cache is used for execution.

2. Econo JIT

This complies only those methods that are called at runtime and removes them from
memory after execution.
3. Pre JIT

This complies entire MSIL code into native code in a single compilation cycle. This is done
at the time of deployment of the application.
CTS and CLS are parts of .NET CLR and are responsible for type safety with in the code. Both
allow cross language communication and type safety. In this article I would like to expose the
relationship between these two.

Common Type System (CTS): CTS stands for Common Type System. It defines the rules
which Common Language Runtime follows when declaring, using, and managing types. The
common type system performs the following functions:

1. It enables cross-language integration, type safety, and high-performance code execution.


2. It provides an object-oriented model for implementation of many programming languages.
3. It defines rules that every language must follow which runs under .NET framework. It
ensures that objects written in different .NET Languages like C#, VB.NET, F# etc. can
interact with each other.

Common Language Specification (CLS) :CLS stands for Common Language Specification and
it is a subset of CTS. It defines a set of rules and restrictions that every language must follow
which runs under .NET framework. The languages which follows these set of rules are said to be
CLS Compliant. In simple words, CLS enables cross-language integration.

For example, one rule is that you cannot use multiple inheritance within .NET Framework. As
you know C++ supports multiple inheritance but; when you will try to use that C++ code within
C#, it is not possible because C# doesn‟t supports multiple inheritance.
One another rule is that you cannot have members with same name with case difference only i.e.
you cannot have add() and Add() methods. This easily works in C# because it is case-sensitive
but when you will try to use that C# code in VB.NET, it is not possible because VB.NET is not
case-sensitive.

Why CTS is Called Common Type System?

In .NET, every Data Type is internally represented by a class or structure. All the classes and
structures related to Data Types are collectively known as CTS. As you know every language
provides its own keywords for Data Types but internally all the languages which run under .NET
framework use the classes and structures available in CTS.
For example, C# has int Data Type and VB.Net has Integer Data Type. Hence a variable
declared as int in C# or Integer in vb.net, finally after compilation, use the same structure Int32
from CTS.
All the structures and classes available in CTS are common for all .NET Languages and purpose
of these is to support language independence in .NET. Hence it is called CTS.

.NET supports two kind of coding


1) Managed Code
2) Unmanaged Code

Managed Code: The resource, which is with in your application domain is, managed code. The
resources that are within domain are faster. The code, which is developed in .NET framework, is
known as managed code. This code is directly executed by CLR with help of managed code
execution. Any language that is written in .NET Framework is managed code.

Managed code uses CLR which in turns looks after your applications by managing memory,
handling security, allowing cross - language debugging, and so on.

Unmanaged Code: The code, which is developed outside .NET, Framework is known as
unmanaged code. Applications that do not run under the control of the CLR are said to be
unmanaged, and certain languages such as C++ can be used to write such applications, which,
for example, access low - level functions of the operating system. Background compatibility with
code of VB, ASP and COM are examples of unmanaged code.

AUTOMATIC MEMORY MANAGEMENT


Memory management is the main concern for any application whether application is window
based or web based. In .Net, CLR has a garbage collector that executes as a part of our program
and responsible for reclaiming the memory of no longer used objects. Garbage collector free the
memory for objects that are no longer referenced and keeps the memory for future allocations.

Advantage of Garbage Collector

1. Allow us to develop an application without having worry to free memory.


2. Allocates memory for objects efficiently on the managed heap.
3. Reclaims the memory for no longer used objects and keeps the free memory for future
allocations.
4. Provides memory safety by making sure that an object cannot use the content of another
object.

Memory Allocation in Managed Heap

The managed heap is a series of allocated memory segments (approx 16Mb in size each) to store
and manage objects. The memory for newly created object is allocated at the next available
location on the managed heap. If there is available free memory, the garbage collector doesn't
search the dead objects for memory reclaim and memory allocations has been done very fast. If
the memory is insufficient to create the object, the garbage collector search the dead objects for
memory reclaim for the newly object.

An object is created using the new operator. This operator first makes sure that the bytes required
by the new object fit in the reserved region (committing storage if necessary). If the object
fits, NextObjPtr points to the object in the heap and object's constructor is called and the new
operator returns the address of the object.

Key points about Garbage Collector

1. All objects in the heap are allocated from one contiguous range of memory address and
heap is divided into generations so that it is easy to eliminate the garbage objects by looking
at only a small fraction of the heap.
2. Gen 0 and Gen 1 occupy a single segment known as the ephemeral segment. Gen 2 is a set
of further segments and the large object heap is yet another group of segments.
3. Almost, all objects with-in a generation are of the same age.
4. The newest objects are created at higher memory address while oldest memory objects are
at lowest memory address with in the heap.
5. The allocation pointer for the new objects marks the boundary between the allocated and
free memory.
6. Periodically the heap is compacted by removing the dead objects and sliding up the live
objects towards the lower memory address end of the heap as shown in above fig.
7. The order of objects (after memory reclaims) in memory remains the same as they were
created.
8. There are never any gaps among the objects in the heap.
9. Only some of the free memory is committed when required and more memory is acquired
from the OS in the reserved address range.

Generations in Managed Heap

The managed heap is organized into three generations so that it can handle short lived and long
lived objects efficiently. Garbage collector first reclaim the short lived objects that occupy a
small part of the heap.

1. Generation 0: This is the youngest generation and contains the newly created objects.
Generation 0 has short-lived objects and collected frequently. The objects that survive the
Generation 0 are promoted to Generation 1.
Example : A temporary object.
2. Generation 1: This generation contains the longer lived objects that are promoted from
generation 0. The objects that survive the Generation 1 are promoted to Generation 2.
Basically this generation serves as a buffer between short-lived objects and longest-lived
objects.
3. Generation 2: This generation contains the longest lived objects that are promoted from
generation 1 and collected infrequently.
Example : An object at application level that contains static data which is available for the
duration of the process.

Garbage Collector Working Phase


1. Marking Phase - In this phase garbage collector finds and creates a list of all live objects.
2. Relocating Phase - In this phase garbage collector updates the references to the objects
that will be compacted.
3. Compacting Phase- In this phase garbage collector reclaims the memory occupied by the
dead objects and compacts the surviving objects. The compacting phase moves the
surviving objects toward the older end of the memory segment.
Note: The large object heap is not compacted, because copying large objects imposes a
performance penalty.

Memory Reclaim Process: Now the garbage collector starts go through the roots and make a
graph of all the objects reachable from the roots. The below fig. shows a heap with allocated
objects. In this heap the application roots directly refer to the objects 1,3,4,6 and object 3 & 6
refers to the objects 8 & 10. Hence all these objects will become the part of the live objects
graph.

The objects which are not reachable from application's roots, are considered as garbage since
these are not accessible by the application. In above heap objects 2,5,7,9 will be considered as
dead objects.
The garbage collector then remove the dead objects from the heap and live objects will move
toward the older end of the memory segment as shown in below fig. Garbage collector also
updates all the references(including root references) to the moving objects in the heap.

PRIVATE AND SHARED ASSEMBLIES

What is Assembly in .NET?

Assemblies are the core building blocks of .NET applications. In simple terms, assembly is the
.dll or .exe file that is created while building any .NET application. You can find many
definitions for assembly over the internet also. In my point of view, assembly is the building
block which is created after a successful build operation of your application.
After compilation of each project, an .exe or .dll file is generated, known as Assembly. The name
of an assembly file is the same as the project name. The assembly of a project present under
bin\Debug folder of that project folder. After successful build of each project an assembly is
generated inside that folder.We can use assembly files by our requirement we may directly take
the assembly file and install into client meachine if it is .exe type or we can consume the file in
another project if the assembly is dll type.

Class Library and Windows Forms Control Library projects generate a .dll assembly where as
Windows Forms Applications, Console Applications, WPF Applications, and Windows Services
projects generate an .exe assembly.

.Exe type assembly are run by their own as well as they provide the support to other in their
execution process so these assembly are know as in-process component where as .dll type
assembly are called as out process component because they are only developed for the purpose to
consume inside .exe type of application.

Note: Every application is a blend of both .dll and .exe assemblies combined together to give
better efficiency.

Types of Assembly:

In .NET, we have two types of assemblies:

1. Private Assembly
2. Shared Assembly

Private Assembly: When we build any project we found a corresponding assembly inside
bin/Debug folder; so by default these assembly is private type.It' private because when we add
that assembly reference to another project then a copy of that assembly created inside that
project. Bellow figure is an example of Private assembly.
Creating an assembly to test if it is private, by default:

Start a new project inside Visual studio of type Class Library and name it as “PAssembly”,we
take class librery because we can consume this project dll file inside another project. Here i am
using VS2012 for my project creation.
in this project you find a file called as Class1.cs. Now, write the following code under the class:

1. public string TestHello() {


2. return "Hello from private assembly";
3. }

Now, compile the project by opening the Solution Explorer, right clicking on the project, and
selecting “Build” or Press "Ctrl+shift+B" which will bulid + compile your project and generate
an assembly with the name as PAssembly.dll.

Note: We can find the path for our assembly in the output window.

Testing the assembly we have created

Open a new project of type Windows, name it as “TestPAssembly”, place a button on the Form,
and set its text as “Call TestHello method of Class1 in PAssembly.dll”. Now, add the reference
of PAssembly.dll from its physical location and write the following code under click of button:

1. PAssembly.Class1 obj = new PAssembly.Class1();


2. MessageBox.Show(obj. TestHello ());

Run the project to test it. Then, go and verify under bin/debug folder of current project where we
can find a copy of PAssembly.dll as it is private assembly.

Note: The advantage of a private assembly is faster execution because it is available in the local
folder, whereas its drawback is that multiple copies get created when multiple projects add the
reference to consume it.

Shared Assemblies: As we saw above while consuming private assembly it always created a
copy of that file inside the project bin/debug folder;so if we want to use that assembly in several
application then we required to put that assembly inside a shared folder. That shared folder in
.Net called as Global Assembly Cache folder. We can add number of assembly inside that folder
and consume that assembly any project.

Note: Before consuming we need to add the assembly inside GAC folder; due to GAC is present
under window directory so read,write and delete can only available when we give the permission
to that folder.

Note: Assemblies deployed in the GAC must have a strong name. When an assembly is added to
the global assembly cache, integrity checks are performed on all files that make up the
assembly.

What a Strong Name is ?

When an assembly created by using Name + Version + Public Key then it's called as strong name

1. Name: Every assembly has it's own name which comes by default when you build your
project.
2. Version: All software comes with Version number; without version number we can not
identify it, so when we created assembly it's comes with default version number called as
"1.0.0.0"
3. Public Key: A public key is a key thrugh which GAC can identify the assembly. As we
know GAC contain all the assembly so to identify uniquely GAC uses this public key.
You can ensure that a name is globally unique by signing an assembly with a strong name. In
particular, strong names satisfy the following requirements:

Strong names guarantee the name uniqueness by relying on unique key pairs. No one can
generate the same assembly name that you can. Strong names protect the version lineage of an
assembly.

A strong name can ensure that no one can produce a subsequent version of your assembly. Users
can be sure that a version of the assembly they are loading comes from the same publisher who
created the version the application was built with.

Strong names provide a strong integrity check. Passing the .NET Framework security checks
guarantees that the contents of the assembly have not been changed since it was built.

Versioning Assemblies
Every assembly has a version number; so to define the version number we have some protocol
through which we can give the version name with their different build. So all this information
can found inside AssemblyInfo.cs file inside each project.

The AssemblyInfo.cs it contain following information :-

 Major Version
 Minor Version
 Build Number
 Revision

EXPLORING VISUAL STUDIO .NET IDE

INTRODUCTION TO C#:
What is C#

C# is pronounced as "C-Sharp". It is an object-oriented programming language provided by


Microsoft that runs on .Net Framework.

By the help of C# programming language, we can develop different types of secured and robust
applications:

o Window applications
o Web applications
o Distributed applications
o Web service applications
o Database applications etc.

C# is approved as a standard by ECMA and ISO. C# is designed for CLI (Common Language
Infrastructure). CLI is a specification that describes executable code and runtime environment.

C# programming language is influenced by C++, Java, Eiffel, Modula-3, Pascal etc. languages.

C++ vs C#

There are many differences and similarities between C++ programming language and C#. A list
of top differences between C++ and C# are given below:

No. C++ C#

1) C++ is a general purpose, case-sensitive, free-form C# is pronounced as "C-Sharp". It is an ob


programming language that supports object-oriented, oriented programming language provided
procedural and generic programming. Microsoft that runs on .Net Framework.

2) In C++, multiple inheritance is possible through In C#, multiple inheritance is not possible
class. through class.

3) In C++, memory management is handled manually. In C#, memory management is handled


automatically.

4) In C++, pointers can be used anywhere in a program. In C#, pointers can be used only in unsafe

5) C++ programming is based on OOPs concept. C# programming is based on Component


OOPs concept.

6) C++ is a programming language that runs on all C# is a programming language that rarely
platforms. outside Windows.

7) C++ programming can be used to create console C# programming can be used to create con
applications. applications, Windows applications, Mo
applications, etc.

Java vs C#

There are many differences and similarities between Java and C#. A list of top differences
between Java and C# are given below:
No. Java C#

1) Java is a high level, robust, secured and object- C# is an object-oriented


oriented programming language developed by programminglanguage developed by Mic
Oracle. that runs on .Net Framework.

2) Java programming language is designed to be run on a C# programming language is designed to


Java platform, by the help of Java Runtime on the Common Language Runtime (CL
Environment (JRE).

3) Java type safety is safe. C# type safety is unsafe.

4) In java, built-in data types that are passed by value are In C#, built-in data types that are passed b
called primitive types. value are called simple types.

5) Arrays in Java are direct specialization of Object. Arrays in C# are specialization of System

6) Java does not support conditional compilation. C# supports conditional compilation using
preprocessor directives.

7) Java doesn't support goto statement. C# supports goto statement.

8) Java doesn't support structures and unions. C# supports structures and unions.

9) Java supports checked exception and unchecked C# supports unchecked exception.


exception.

C# is a modern, general-purpose, object-oriented programming language developed by


Microsoft and approved by European Computer Manufacturers Association (ECMA) and
International Standards Organization (ISO).

C# was developed by Anders Hejlsberg and his team during the development of .Net
Framework.

C# is designed for Common Language Infrastructure (CLI), which consists of the executable
code and runtime environment that allows use of various high-level languages on different
computer platforms and architectures.

The following reasons make C# a widely used professional language −


 It is a modern, general-purpose programming language
 It is object oriented.
 It is component oriented.
 It is easy to learn.
 It is a structured language.
 It produces efficient programs.
 It can be compiled on a variety of computer platforms.
 It is a part of .Net Framework.
Strong Programming Features of C#
Although C# constructs closely follow traditional high-level languages, C and C++ and being
an object-oriented programming language. It has strong resemblance with Java, it has numerous
strong programming features that make it endearing to a number of programmers worldwide.

Following is the list of few important features of C# −

 Boolean Conditions
 Automatic Garbage Collection
 Standard Library
 Assembly Versioning
 Properties and Events
 Delegates and Events Management
 Easy-to-use Generics
 Indexers
 Conditional Compilation
 Simple Multithreading
 LINQ and Lambda Expressions
 Integration with Windows

C# History

History of C# language is interesting to know. Here we are going to discuss brief history of C#
language.
C# is pronounced as "C-Sharp". It is an object-oriented programming language provided
by Microsoft that runs on .Net Framework.

Anders Hejlsberg is known as the founder of C# language.

It is based on C++ and Java, but it has many additional extensions used to perform component
oriented programming approach.

C# has evolved much since their first release in the year 2002. It was introduced with .NET
Framework 1.0 and the current version of C# is 5.0.

Important features introduced in each version of C# are given below.

C# FEATURES:

C# is object oriented programming language. It provides a lot of features that are given below.

1) Simple-C# is a simple language in the sense that it provides structured approach (to break the
problem into parts), rich set of library functions, data types etc.
2) Modern Programming Language-C# programming is based upon the current trend and it is
very powerful and simple for building scalable, interoperable and robust applications.

3) Object Oriented-C# is object oriented programming language. OOPs makes development and
maintenance easier where as in Procedure-oriented programming language it is not easy to
manage if code grows as project size grow.

4) Type Safe-C# type safe code can only access the memory location that it has permission to
execute. Therefore it improves a security of the program.

5) Interoperability-Interoperability process enables the C# programs to do almost anything that a


native C++ application can do.

6) Scalable and Updateable-C# is automatic scalable and updateable programming language. For
updating our application we delete the old files and update them with new ones.

7) Component Oriented-C# is component oriented programming language. It is the predominant


software development methodology used to develop more robust and highly scalable
applications.

8) Structured Programming Language- C# is a structured programming language in the sense


that we can break the program into parts using functions. So, it is easy to understand and modify.

9) Rich Library - C# provides a lot of inbuilt functions that makes the development fast.

10) Fast Speed - The compilation and execution time of C# language is fast.

C# Version History

Version .NET Framework Visual Studio Important Features

C# 1.0 .NET Framework Visual Studio .NET First release of C#


1.0/1.1 2002

C# 2.0 .NET Framework Visual Studio 2005  Generics


2.0  Partial types
 Anonymous methods
 Nullable types
 Iterators
 Covariance and contravariance

C# 3.0 .NET Framework Visual Studio 2008  Auto-implemented properties


3.0\3.5  Anonymous types
 Query expressions
 Lambda expression
 Expression trees
 Extension methods

C# 4.0 .NET Framework Visual Studio 2010  Dynamic binding


4.0  Named/optional arguments
 Generic covariant and
contravariant
 Embedded interop types

C# 5.0 .NET Framework Visual Studio  Asynchronous members


4.5 2012/2013  Caller info attributes

C# 6.0 .NET Framework Visual Studio  Static imports


4.6 2013/2015  Exception filters
 Property initializers
 Expression bodied members
 Null propagator
 String interpolation
 nameof operator
 Dictionary initializer

C# 7.0 .NET Core Visual Studio 2017  Static imports


 Exception filters
 Property initializers
 Expression bodied members
 Null propagator
 String interpolation
 nameof operator
 Dictionary initializer

ABSTRACTION:

Abstraction is one of the principle of object oriented programming. It is used to display only
necessary and essential features of an object to outside the world. Means displaying what is
necessary and encapsulate the unnecessary things to outside the world. Hiding can be achieved
by using "private" access modifiers.

Note - Outside the world means when we use reference of object then it will show only
necessary methods and properties and hide methods which are not necessary.

Implementation of Abstraction

To implement abstraction let's take an example of a car. We knows a car, Car is made of name of
car, color of car, steering, gear, rear view mirror, brakes, silencer, exhaust system, diesal engine,
car battery, car engine and other internal machine details etc.
Now lets think in terms of Car rider or a person who is riding a car. So to drive a car what a car
rider should know from above category before he starts a car driving.

Necessary things means compulsory to know before starting a car

1. Name of Car
2. Color of Car
3. Steering
4. Rear View Mirror
5. Brakes
6. Gear

Unnecessary things means not that compulsory to know for a Car rider
1. Internal Details of a Car
2. Car Engine
3. Diesal Engine
4. Exhaust System
5. Silencer

Now above same thing let me put in the coding style using C#
01 public class Car
02
03 private string _nameofcar = "My Car";
04 private string _colorofcar = "Red";
05
06 public string NameofCar
07
08 set
09
10 _nameofcar = value;
11 }
12 get
13
14 return _nameofcar;
15 }
16 }
17
18 public string ColorofCar
19
20 set
21
22 _colorofcar = value;
23 }
24 get
25
26 return _colorofcar;
27 }
28 }
29
30 public void Steering()
31
32 Console.WriteLine("Streering of Car");
33 }
34
35 public void RearViewMirror()
36
37 Console.WriteLine("RearViewMirror of Car");
38 }
39
40 public void Brakes()
41
42 Console.WriteLine("Brakes of Car");
43 }
44 public void Gear()
45
46 Console.WriteLine("Gear of Car");
47 }
48
49
50 private void InternalDetailsofCar()
51
52 Console.WriteLine("InternalDetailsofCar of Car");
53 }
54
55 private void CarEngine()
56
57 Console.WriteLine("CarEngine of Car");
58 }
59
60 private void DiesalEngine()
61
62 Console.WriteLine("DiesalEngine of Car");
63 }
64
65 private void ExhaustSystem()
66
67 Console.WriteLine("ExhaustSystem of Car");
68 }
69
70 private void Silencer()
71
72 Console.WriteLine("Silencer of Car");
73 }
74
75
76 }

As you can see from above code that necessary methods and properties exposed by using
"public" access modifier and unnecessary methods and properties (not compulsary) hidden by
using "private" access modifier.

As you see to achieve abstraction we used access modifier "public" to expose some methods and
properties to outside the class or world.
As you see to achieve abstraction we used access modifier "private" to hide some methods and
properties from outside the class or world.
Finally lets check by creating an object of above class "Car" in our main program of a console
application and by using object lets see weather we are getting all exposed necessary methods
and properties.

1 class Program
2
3 static void Main(string[] args)
4
5 Car objCar = new Car();
6
7 }
8}

Conclusion

Sucessfully we have exposed necessary methods and properties to outside the world or class.
This is how we need to implement abstraction or we can achieve abstraction in our code or
application

You might also like