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

C# Notes

The .NET Framework is a software development framework developed by Microsoft that provides a runtime environment and libraries for building various application types on Windows. It includes programming languages like C# and Visual Basic and supports desktop, web, mobile, and gaming applications. The framework promotes language interoperability, portability, type safety, and automatic memory management to improve code quality and developer productivity.

Uploaded by

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

C# Notes

The .NET Framework is a software development framework developed by Microsoft that provides a runtime environment and libraries for building various application types on Windows. It includes programming languages like C# and Visual Basic and supports desktop, web, mobile, and gaming applications. The framework promotes language interoperability, portability, type safety, and automatic memory management to improve code quality and developer productivity.

Uploaded by

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

The .

NET Framework is a software development framework developed by Microsoft that


provides a runtime environment and a set of libraries and tools for building and running
applications on Windows operating systems. The framework includes a variety of
programming languages, such as C#, F#, and Visual Basic, and supports a range of application
types, including desktop, web, mobile, and gaming applications.

Characteristics of .NET Framework:

1. Language Interoperability: Language Interoperability means code written in any


language can be used by other languages and there is an access provided to COM
components in the System. In other words, this is the ability of code to interact with
code which is written using a different programming language. It can help to maximize
code reusability and therefore improve the efficiency of the development process.

2. Portable: The .NET Framework provides a common platform to write portable


programs using different languages of .NET environment, based on open Internet
standards which allow different devices, software’s and applications to work together
across a wide and dispersed network of networks.

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.

5. Performance: Its CLR environment promotes safe execution of code, eliminates


performance bottlenecks through its garbage collector, minimizes software development
conflicts through namespaces and avoids versioning conflicts through assembly
manifest.

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.

9. Dynamic Language Runtime: The dynamic language runtime is a new runtime


environment that adds a set of services for dynamic languages to the Common Language
Runtime. The CLR makes it easier to develop dynamic languages run on the .NET
framework and to add dynamic features to statically typed language.

10. Automatic memory management: While developing applications developers had to


develop an eye on system resource like memory. ..NET takes this worry away from
developer by handling memory on its own. The garbage collector takes care of freeing
unused objects at appropriate intervals.
11. A major feature of NET framework CLR is that the runtime automatically handles the
allocate and release of an object’s memory resources Automatic memory management
enhances code quality and developer’s productivity without negatively impacting
performance The Garbage Collector responsible for collecting the objects no longer
referenced by application.

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.

.NET Technology: .NET technology of collection or set of technologies to develop


windows and web applications. The technology of .Net is developed by Microsoft and was
launched in Feb. 2002, by basic definition, Microsoft’s new Internet Strategy. It was
originally called NGWS (Next Generation Web Services). It is considered to be one of the
most powerful, popular, and very useful Internet Technology available today.
Building Blocks of .NET Platform or Components of .NET Platform
 CLR (Common Language Runtime)
 CTS (Common Type System)
 BCL (Base Class Library)
 CLS (Common Language Specification)
 FCL (Framework Class Library)
 .NET Assemblies
 XML Web Services
 Window Services

CLR (common language runtime)


It is an important part of a .NET framework that works like a virtual component
of the .NET Framework to executes the different languages program like c#, Visual
Basic, etc. A CLR also helps to convert a source code into the byte code, and this byte
code is known as CIL (Common Intermediate Language) or MSIL (Microsoft
Intermediate Language). After converting into a byte code, a CLR uses a JIT compiler at
run time that helps to convert a CIL or MSIL code into the machine or native code.

CTS (Common Type System)


It specifies a standard that represent what type of data and value can be defined and
managed in computer memory at runtime. A CTS ensures that programming data defined
in various languages should be interact with each other to share information. For
example, in C# we define data type as int, while in VB.NET we define integer as a data
type.

BCL (Base Class Library)


The base class library has a rich collection of libraries features and functions that help to
implement many programming languages in the .NET Framework, such as C #, F #,
Visual C ++, and more. Furthermore, BCL divides into two parts:

User defined class library


Assemblies - It is the collection of small parts of deployment an application's part. It
contains either the DLL (Dynamic Link Library) or exe (Executable) file.

 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.

Predefined class library

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.

CLS (Common language Specification)


It is a subset of common type system (CTS) that defines a set of rules and regulations
which should be followed by every language that comes under the .net framework. In
other words, a CLS language should be cross-language integration or interoperability. For
example, in C# and VB.NET language, the C# language terminate each statement with
semicolon, whereas in VB.NET it is not end with semicolon, and when these statements
execute in .NET Framework, it provides a common platform to interact and share
information with each other.

Microsoft .NET Assemblies

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.

FCL (Framework Class Library)

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.

Key Components of FCL


 Object type
 Implementation of data structure
 Base data types
 Garbage collection
 Security and database connectivity
 Creating common platform for window and web-based application

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

The Role of Common Intermediate Language or Microsoft Intermediate


Language

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.

 A Common Language Infrastructure (CLI) assembly is created by assembling the MSIL.


This assembly is basically a compiled code library that is used for security, deployment,
versioning, etc. and it is of two types i.e. process assembly (EXE) and library assembly
(DLL).

 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:

Description of the assembly.


 Identity (name, version, culture, public key).
 The types that are exported.
 Other assemblies that this assembly depends on.
 Security permissions needed to run.
Description of types.
 Name, visibility, base class, and interfaces implemented.
 Members (methods, fields, properties, events, nested types).
 Attributes.
 Additional descriptive elements that modify types and members.

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

COMPILING CIL TO PLATFORM-SPECIFIC INSTRUCTIONS


Due to the fact that 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 termed a just-in-time (JIT) 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 that is to be deployed to a handheld
device (such as a Pocket PC), 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
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.
Furthermore, as a given Jitter compiles CIL instructions into corresponding machine
code, it will cache the results in memory in a manner suited to the target operating system.
In this way, if a call is made to a method named PrintDocument(), the CIL instructions are
compiled into platform specific instructions on the first invocation and retained in memory
for later use. Therefore, the next time PrintDocument() is called, there is no need to
recompile the CIL.
C# Namespace

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
}

Accessing the Members of Namespace


The members of a namespace are accessed by using dot(.) operator. A class in C# is fully known
by its respective namespace.
Syntax:
[namespace_name].[member_name]
Example:
Using System.Drawing;
BUILDING C# ASSEMBLY USING CSC.EXE

You might also like