Common Language Runtime (CLR)
Common Language Runtime (CLR)
Common Language Runtime (CLR)
NET Framework
The .NET Framework, introduced by Microsoft, aims at integrating various programming
languages and services. The .NET Framework is designed to make significant improvements in
code reuse, code specialization, resource management, Multilanguage development, security,
deployment, and administration. The .NET Framework consists of all the technologies that help
in creating and running robust, scalable, and distributed applications.
• .NET Products
• .NET Services
• .NET Framework
.NET Products: - .NET products aim at allowing developers to create applications, which are
capable of interacting seamlessly with each other. All .NET products use eXtensible Markup
Language (XML) for describing and exchanging data between applications. An example of a
.NET product is Visual Studio .NET.
.NET Services: - .NET helps us to create software as Web services. A Web Service is an
application or business logic that is accessible through standard Internet protocols such as
Hypertext Transfer Protocol (HTTP) and Simple Object Access Protocol (SOAP). We can
identify the service by a Uniform Resource Locator (URL).
The .NET Framework: - It is the foundation for designing, developing, and deploying
applications. It is the core of the .NET infrastructure because it exists as a layer between the
.NET applications and the underlying operating system.
CLR consists of a set of common rules followed by all the languages of the .NET Framework.
This set of rules is known as Common Language Specification (CLS). CLS enables an object or
application to interact with the objects or applications of other languages. The classes that follow
the rules specified by CLS are termed as CLS-compliant classes. The classes defined in the .NET
Framework class library are CLS-compliant.
One of the specifications defined in CLS is CTS, which provides a type system that is common
across all languages. CTS define how data types are declared, used, and managed in the code at
run time.
• Namespaces.
• Assemblies
• Windows Forms
• Web Forms
• Console Applica
.NET provides a program interface, Web Services, to communicate with remote components.
The Visual Studio .NET
The Visual Studio .NET IDE provides we with a common interface for developing various kinds
of projects for the .NET Framework. The IDE also provides we with a centralized location for
designing the user interface for an application, writing code, and compiling and debugging the
application. In Visual Studio .NET, an application can be made up of one or more items, such as
files and folders.
• To organize these items efficiently, Visual Studio .NET has provided two types of
containers:
• Project: It typically contains items that make up the application. These items are
interrelated.
To create a console application in Visual Studio, we need to create a project. To create a project,
we need to perform the following steps:
To compile and execute the application, we need to perform the following steps:
By design, C# is the programming language that most directly reflects the underlying Common
Language Infrastructure (CLI). Most of its intrinsic types correspond to value-types implemented
by the CLI framework. However, the language specification does not state the code generation
requirements of the compiler: that is, it does not state that a C# compiler must target a Common
Language Runtime, or generate Common Intermediate Language (CIL), or generate any other
specific format. Theoretically, a C# compiler could generate machine code like traditional
compilers of C++ or Fortran.
2. C# supports a strict Boolean datatype, bool. Statements that take conditions, such as
while and if, require an expression of a type that implements the true operator, such as the
Boolean type.
3. In C#, memory address pointers can only be used within blocks specifically marked as
unsafe, and programs with unsafe code need appropriate permissions to run. Most object
access is done through safe object references, which always either point to a "live" object
or have the well-defined null value; it is impossible to obtain a reference to a "dead"
object (one which has been garbage collected), or to a random block of memory. An
unsafe pointer can point to an instance of a value-type, array, string, or a block of
memory allocated on a stack.
6. Multiple inheritance is not supported, although a class can implement any number of
interfaces.
7. C# is more type safe than C++. The only implicit conversions by default are those which
are considered safe, such as widening of integers. This is enforced at compile-time,
during JIT, and, in some cases, at runtime. Any user-defined conversion must be
explicitly marked as explicit or implicit, unlike C++ copy constructors and conversion
operators, which are both implicit by default.
10. Checked exceptions are not present in C# (in contrast to Java). This has been a conscious
decision based on the issues of scalability and versionability.
CTS separates datatypes into two categories
Value types:-Value types are plain aggregations of data. Instances of value types do not have
referential identity or referential comparison semantics - equality and inequality comparisons for
value types compare the actual data values within the instances, unless the corresponding
operators are overloaded. Value types are derived from System.ValueType, always have a
default value, and can always be created and copied. Some other limitations on value types are
that they cannot derive from each other (but can implement interfaces) and cannot have an
explicit default (parameterless) constructor. Examples of value types are some primitive types,
such as int (a signed 32-bit integer), float (a 32-bit IEEE floating-point number), char (a 16-bit
Unicode code unit), and System.DateTime (identifies a specific point in time with nanosecond
precision). Other examples are enum (enumerations) and struct (user defined structures).
Reference types: - Reference types have the notion of referential identity - each instance of a
reference type is inherently distinct from every other instance, even if the data within both
instances is the same. This is reflected in default equality and inequality comparisons for
reference types, which test for referential rather than structural equality, unless the corresponding
operators are overloaded (such as the case for System.String). Examples of reference types are
object (the ultimate base class for all other C# classes), System.String (a string of Unicode
characters), and System.Array (a base class for all C# arrays).
• After writing the program in a Notepad, we need to compile and execute it to get the
desired output.
• The compiler converts the source code that we write into the machine code, which the
computer can understand.
• The following steps are needed to compile and execute a C# program.
1. Save the code written in the Notepad with an extension .cs.
2. To compile the code, we need to go to the Visual Studio 2005 Command
Prompt window. Select StartàAll ProgramsàMicrosoft Visual Studio
2005àVisual Studio ToolsàVisual Studio 2005 Command Prompt. The Visual
Studio 2005 Command Prompt window is displayed to compile the program.
3. In the Visual Studio 2005 Command Prompt window, move to the location
where the programs file is saved.
4. Compile the program file by using the following command:
csc myexample.cs
5. To execute the code, type the following in the command prompt:
myexample.exe
ADO.NET
ADO.NET is a model used by .NET applications to communicate with a database for retrieving,
accessing, and updating data. It uses a structured process flow to interact with a database.It is a
part of the base class library that is included with the Microsoft .NET Framework. It is
commonly used by programmers to access and modify data stored in relational database systems,
though it can also access data in non-relational sources. ADO.NET is sometimes considered an
evolution of ActiveX Data Objects (ADO) technology, but was changed so extensively that it
can be considered an entirely new product.
Features of ADO.NET
Disconnected data architecture — Applications connect to the database only while
retrieving and updating data.
Data cached in datasets — ADO.NET is based on a disconnected data structure.
Therefore, the data is retrieved and stored in datasets.
Data transfer in XML format — ADO.NET uses XML for transferring information from
a database into a dataset and from the dataset to another component.
Interaction with the database is done through data commands.
A dataset
A DataReader object
Is used for connecting to a database, retrieving data, and storing the data.
Is of two types:
ConnectionString property
Open()method
Close()method
Data adapter
Data command
Data reader
Is used to retrieve data from a data source in a read-only and forward-only mode.
Stores a single row at a time in the memory.
Commonly used methods:
Read()
Close()
Dataset
Is a disconnected, cached set of records that are retrieved from a database.
Is present as a DataSet class in the System.Data namespace.