C# Notes
C# Notes
3. Type Safety: During program execution, the type checker ensures that all objects and
values, and the references to those objects and values, have a valid type. For example,
the type checker ensures that only an integer value is assigned to an integer variable.
The type checker also ensures that only valid operations are performed on the objects or
values.
4. Managed Multithreading Support: Applications running in the CLR can utilize the
managed multithreading support. Multithreading requires careful programming For most
tasks, you can reduce complexity by queuing requests for execution by thread pool
threads.
6. Side by Side Execution: The NET Framework allows you to deploy multiple versions
of an application on a system by using assemblies. Assemblies are the deployment units
in the NET Framework. An assembly contains the IL code and metadata. The metadata
contains information such as the version of the other assemblies on which the assembly
depends. The Common Language Runtime uses the version lo information in the
metadata to determine application dependencies and enables you to execute multiple
versions of an application side-by-side.
7. Common Type System: This provides the necessary data types, values, and object
types, which you need to develop applications in different languages. All the NET
languages share Common Type System. This implies that a String in Visual Basic .NET
is the same as a String in Visual C# or in Visual C++ NET. All the NET languages have
access to the same class libraries. In addition, all languages are equally powerful. There
is no superior language in .NET i.e. Visual Basic .NET is as powerful as Visual C# or
Visual C++ NET.
8. Parallel Computing: The NET Framework 4.0 introduces a new programming model
for writing multithreaded and asynchronous code that greatly simplifies the work of
application and library developers.
12. Language Independence: Language Independence makes use of the power of various
languages in one platform. It means programmers can develop their applications in any
of the language supported by NET framework .NET framework supports various
programming languages such as Microsoft Visual Basic NET, Microsoft Visual J# NET
etc. After Compilation the source code of all these languages converted into Common
Intermediate Language (CL) that enhances Language Independence.
13. Base Class Library: The Base Class Library (BCL) is a library of functionality
available to all languages in the NET Framework. The BCL provides classes that
encapsulate a number of common functions including file reading and writing graphic
rendering, database interaction, XML document manipulation.
14. Enhancements to ASP. NET & ADO .NET: ASP. NET & ADO .NET is a subset
of .NET framework. .NET framework provides enhancement to this technology.
15. Security: Windows platform was always criticized for poor security mechanisms.
Microsoft has taken great efforts to make .NET platform safe and secure for enterprise
applications Features such as type safety, code access security etc.
16. Intellisense:.NET IDE supports Intellisense feature that helps in automatic code
compilations. It helps in reducing typo effects and mistakes.
There are three significant phases of the development of .NET technology.
OLE Technology
COM Technology
.NET Technology
OLE Technology: OLE (Object Linking and Embedding) is one of the technologies of
Microsoft’s component document. Basically, its main purpose is to link elements from
different applications with each other.
COM Technology: The technology of the Microsoft Windows family of the operating
system, Microsoft COM (Common Object Model) enables various software components
to communicate. COM is mostly used by developers for various purposes like creating
reusable software components, linking components together to build applications, and also
taking advantage of Windows services. The objects of COM can be created with a wide
range of programming languages.
In LL, it uses code reusability, whereas in exe it contains only output file/ or
application.
DLL file can't be open, whereas exe file can be open.
DLL file can't be run individually, whereas in exe, it can run individually.
In DLL file, there is no main method, whereas exe file has main method.
Namespace - It is the collection of predefined class and method that present in .Net. In
other languages such as, C we used header files, in java we used package similarly we
used "using system" in .NET, where using is a keyword and system is a namespace.
A .NET assembly is the main building block of the .NET Framework. It is a small unit of
code that contains a logical compiled code in the Common Language infrastructure (CLI),
which is used for deployment, security and versioning. It defines in two parts (process)
DLL and library (exe) assemblies. When the .NET program is compiled, it generates a
metadata with Microsoft Intermediate Language, which is stored in a file called Assembly.
It provides the various system functionality in the .NET Framework, that includes classes,
interfaces and data types, etc. to create multiple functions and different types of
application such as desktop, web, mobile application, etc. In other words, it can be defined
as, it provides a base on which various applications, controls and components are built
in .NET Framework.
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.
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
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.
7) Component Oriented
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.
The Microsoft Intermediate Language (MSIL), also known as the Common Intermediate
Language (CIL) is a set of instructions that are platform independent and are generated by the
language-specific compiler from the source code. The MSIL is platform independent and
consequently, it can be executed on any of the Common Language Runtime supported
environments such as Windows .NET runtime.
The MSIL is converted into a particular computer environment specific machine code by the JIT
compiler. This is done before the MSIL can be executed. Also, the MSIL is converted into the
machine code on a requirement basis i.e. the JIT compiler compiles the MSIL as required rather
than the whole of it.
Execution process in Common Language Runtime (CLR): The execution process that includes
the creation of the MSIL and the conversion of the MSIL into machine code by the JIT compiler
is given as follows:
The source code is converted into the MSIL by a language-specific compiler in the
compile time of the CLR. Also, along with the MSIL, metadata is also produced in the
compilation. The metadata contains information such as the definition and signature of
the types in the code, runtime information, etc.
The JIT compiler then converts the Microsoft Intermediate Language(MSIL) into the
machine code that is specific to the computer environment that the JIT compiler runs on.
The MSIL is converted into the machine code on a requirement basis i.e. the JIT compiler
compiles the MSIL as required rather than the whole of it.
The machine code obtained using the JIT compiler is then executed by the processor of
the computer.
METADATA
Metadata is binary information describing your program that is stored either in a common
language runtime portable executable (PE) file or in memory. When you compile your code into
a PE file, metadata is inserted into one portion of the file, and your code is converted to
Microsoft intermediate language (MSIL) and inserted into another portion of the file. Every type
and member that is defined and referenced in a module or assembly is described within metadata.
When code is executed, the runtime loads metadata into memory and references it to discover
information about your code's classes, members, inheritance, and so on.
Metadata describes every type and member defined in your code in a language-neutral
manner. Metadata stores the following information:
ASSEMBLY MANIFEST
Every assembly, whether static or dynamic, contains a collection of data that describes
how the elements in the assembly relate to each other. The assembly manifest contains this
assembly metadata. An assembly manifest contains all the metadata needed to specify the
assembly's version requirements and security identity, and all metadata needed to define the
scope of the assembly and resolve references to resources and classes. The assembly manifest
can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL)
code or in a standalone PE file that contains only assembly manifest information.
The following illustration shows the different ways the manifest can be stored.
For an assembly with one associated file, the manifest is incorporated into the PE file to form a
single-file assembly. You can create a multiple file assembly with a standalone manifest file or
with the manifest incorporated into one of the PE files in the assembly
Namespaces are used to organize the classes. It helps to control the scope of methods and
classes in larger .Net programming projects. In simpler words you can say that it provides a way
to keep one set of names(like class names) different from other sets of names. The biggest
advantage of using namespace is that the class names which are declared in one namespace will
not clash with the same class names declared in another namespace. It is also referred as named
group of classes having common features. The members of a namespace can be namespaces,
interfaces, structures, and delegates.
Defining a Namespace
To define a namespace in C#, we will use the namespace keyword followed by the name of the
namespace and curly braces containing the body of the namespace as follows:
Syntax:
namespace name_of_namespace {
// Namespace (Nested Namespaces)
// Classes
// Interfaces
// Structures
// Delegates
}