You are on page 1of 26

UNIT-I

Introduction to C#
• Introducing C#
• writing a C# Program
• Literals
• Data Types
• Operators
• Expressions
• Flow Control
• More About Variables
• Boxing and unboxing
• Debugging and Error Handling.
Microsoft introduces .NET Framework.
.NET
i. NET stands for Network Enabled Technology (Internet).
ii. In .NET, dot (.) refers to Object-Oriented, and NET refers to the
internet.
iii. So, the complete .NET means through Object-Oriented where
user can implement internet-based applications.
What is not .NET?
.NET is not an Operating system.
.NET is not a database
It is not an ERP application.
.NET is not a Testing Tool.
It is not a programming language.
What is COM?
i. COM stands for Component Object Model.
ii. The COM is one of the Microsoft Frameworks.
iii. Using this Framework, user can develop Windows Applications
(Desktop or Standalone Applications for Windows OS) as well
as Web Applications.
iv. In earlier COM, VB is the programming language that is used
to implement Windows applications and ASP is the technology
used to implement web applications.
What are the disadvantages of COM?
There are two major disadvantages of the COM Framework. They are
as follows:
• Incomplete Object-Oriented Programming means it will not
support all the features of OOPs.
• Platform Dependent means COM applications can run on only
Windows OS.
What is .NET?
•.NET is a free and open-source application platform supported by
Microsoft.
• .Net is a new framework for developing Web-Based and Windows
Based Applications within the Microsoft Environment.
• .Net is powerful tool used to build Distributed Computing
Applications.
.NET Application

.NET Framework

Operating System + Hardware


• .Net Framework is designed for windows operating system only.
• There is another company known as Novel designed separate
framework known by MONO framework .Using this framework we
can run MSIL on different operating systems like LINUX, Solaris,
Mac OS etc.,

• .Net is platform dependent using .Net Framework but Independent


using MONO framework.
i. .NET Framework supports more than 60 programming
languages of which 11 programming languages are designed
and developed by Microsoft.
ii. The remaining Non-Microsoft Languages are supported
by .NET Framework but not designed and developed by
Microsoft.
According to Microsoft, .NET is a Free, Cross-Platform, Open-
Source developer platform for building many different types of
applications.
With .NET, user can
1. Use multiple languages (C#, VB, F#, etc.),
2. Editors (Visual Studio, Visual Studio Code, Visual Studio for
Mac, OmniSharp, JetBrains Rider, etc), and
3. Libraries to build for Web, Mobile, Desktop, Games, IoT, and
more.

Cross Platform:
Whether you are working in C#, F#, or Visual Basic, your code will
run on any compatible operating system. You can build many types of
apps with .NET. Some are Cross-Platform, and some target a specific
set of operating systems and devices.
Libraries:
i. To extend functionality, Microsoft and others maintain a healthy .NET package
ecosystem.
ii. NuGet is a package manager built specifically for .NET that contains over
100,000 packages.

Framework
iii. A framework is a software. Or you can say a framework is a collection of
many small technologies integrated together to develop applications that can be
executed anywhere.

.NET Framework Provide


The components of .NET are
iv. CLR,
v. Garbage Collector,
vi. JIT Compiler and
vii. base class library.
BCL
i. Base Class Libraries (BCL) are designed by Microsoft.
ii. Without BCL user can’t write any code in .NET.
iii. So, BCL is also known as the basic building block of .NET
Programs.
iv. These are installed into the machine when user installed the .NET
framework.
v. BCL contains pre-defined classes and these classes are used for
the purpose of application development.

The physical location of BCL is C:\Windows\assembly

These Base class Libraries are exist either in the form


of .dll(Dynamic Link Library) or .exe(Executable File)
JIT
i. JIT stands for the Just-in-Time compiler.
ii. It is the component of CLR that is responsible for
converting MSIL code into Native Code.
iii. Native code is code that is directly understandable by the
operating system.

CLR
iv. CLR (Common Language Runtime)
v. CLR is responsible for providing common syntax, automatic
memory management, and common data type.
vi. Also, the responsibility of CLR is generating native code from
MSIL Code.
CLS (Common Language Specification)
• Every programming language has its own syntactical rules &
specification to write their code.
• So , one programming language cannot understand other
programming languages specification.
• CLS has a common specification for all programming
languages.
• Any language compiler should follow this at the time of
compilation & should generate MSIL.
• This CLS is common to all languages of Managed Code
Execution of .Net
CTS(Common Type System)
i. Managed code execution process of .Net supports many
languages.
ii. Its common that every programming language has its own
data types.
iii. So ,one language can’t understand others data type
specification.
iv. CLR contains its own data types which are common to all
the programming languages, this is CTS.
v. CTS is divided into 2 types
 Value Type
 Reference Type
GC(Garbage Collector)
i. GC is the one who frees up the memory for CLR’s execution
process.
ii. It is responsible for Automatic Memory Management.

What is Automatic Memory Management and How Garbage


Collector is responsible for this?
Ans:
 whenever Garbage Collector starts working ,first it searches
for the object which is currently being used in the memory and
objects which are not used , means the Idle/Unreachable
objects which are not participating in any operation.
 After identifying the types Garbage Collector removes the
Idle/Unreachable objects and kept the objects in use. So that
memory can be allocated for newly created objects. This
continues process is Automatic Memory Management.
Technologies supported by the .NET framework are as follows
i. ASP.NET (Active Server Pages.NET) – MVC, Web API,
Core MVC, Core Web API, Core Blazor, etc.
ii. ADO.NET (Active Data Object.NET)
iii. WCF (Windows Communication Foundation)
iv. WPF (Windows Presentation Foundation)
v. WWF (Windows Workflow Foundation)
vi. AJAX (Asynchronous JavaScript and XML)
vii. LINQ (Language Integrated Query)
viii. Entity Framework
What are Technology and its Needs?
i. Technology is always designed for a particular purpose.
ii. For example, the development of web-related applications in .NET
using the technology ASP.NET.
iii. But the technology does not offer any specific rules for writing the
programs.
iv. That’s why technology can’t be implemented individually.
v. VB.NET, C#.NET, and F#.NET are programming languages.
vi. Using any of these languages we can implement windows/desktop
applications individually. Every language is having its own compiler
11 Programming Languages which are designed and developed
by Microsoft are:
C#.NET
VB.NET
C++.NET
J#.NET
F#.NET
JSCRIPT.NET
WINDOWS POWERSHELL
IRON RUBY
IRON PYTHON
C OMEGA
ASML(Abstract State Machine Language)
Code Execution in .Net
1. In .Net code is compiled twice.
2. In first compilation source code is compiled by respective
language compiler and an intermediately code is generated
known as MSIL.
3. In second compilation MSIL is converted into Native code
using CLR.
4. Always first compilation is slow and second compilation fast.
5. MSIL is only CPU Independent and will run only on Windows
OS only using .Net Framework, because ,.Net Framework is
designed for Windows Operating System only.
6. There is another company known as Novel designed separate
framework known by MONO framework using this framework
we can run MSIL on different operating systems like Linux,
Solars.etc.,
7. .Net is platform dependent using .net Framework but
independent using Mono Framework.
8. Here in .Net source code means code that has been written in any
language supported by .Net( C#, VB,C++,J#,F#,COBOL)
9.Every Programming has its own compiler.
10.Code might have been written in any programming language and
is compiled by any language compiler code will come into a common
form that is MSIL.
C#
C# Code
Compiler

MSIL Code
VB.Net VB.NET Native
CLR Execu
Code Compiler Code
te

J# J#
Code Compiler

Every programming language has its own language compiler, so in the


above figure LC belongs to that respective language. Source codes might
have been written in any programming language and is compiled by any
language compiler but code will come into a common form which is
CIL/MSIL.
In the .NET framework, the code is compiled twice.
• In the 1st compilation, the source code is compiled by the
respective language compiler and generates the intermediate
code which is known as MSIL (Microsoft Intermediate
Language) or IL (Intermediate language
code), or Managed Code.
• In the 2nd compilation, MSIL is converted into Native
code (native code means code specific to the Operating
system so that the code is executed by the Operating System)
and this is done by CLR.
Always 1st compilation is slow and 2nd compilation is fast.
1st Compilation
2nd Compilation

.Net Source Native Code


LC MSIL CLR Execu
Code Code
te
Managed Code and Unmanaged Code
As source code is compiled by its respective language compiler
and after compilation is completed a common form of code that
is MSIL is generated. That MSIL code then used by CLR to
convert it into Native Code/Machine Code, then that code (source
code) is executed.
 Managed Code – Source code for which MSIL is generated, that
code execution process is Managed.
 Unmanaged Code – Source code for which MSIL is not
generated is Unmanaged Code
Unmanaged Code

Managed LC MSIL Native Code


Code CLR
Code Execute

Operating System

You might also like