Unit 1 Intro to DOT NET Architecture
Unit 1 Intro to DOT NET Architecture
NET Technologies
(01CE1602)
6th Semester
4 Credits
Prof. Ravikumar R N
Dept. of Computer Engineering
Net Technologies are blend of technologies supported
by Microsoft .Net Framework that allows user to create
Objectives various applications.
Students will be able to work with various technologies
provided by Microsoft .NET platform.
To Review the components of .Net Framework
To practice Web based application
Course To create web applications using MVC framework
Outcomes To practice basic database application using ADO.net
To designing, developing, and deploying APIs
Unit 1
Introduction to .NET Framework and C#
Introduction to .NET Framework Architecture
CLR
Assemblies
Basics of C#
Class
Object
Method
Contents
Access Modifiers
Constructors
Abstract Class
Inheritance
Interface
Polymorphism
Exception Handling
The .Net 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.
History of The Microsoft .Net framework has come a long way
since then, and the current version is .Net Framework
.NET 6.0.
The Microsoft .Net framework can be used to create
both – Form-based and Web-based applications. Web
services can also be developed using the .Net
framework.
.NET Framework is a software development framework
for building and running applications on Windows.
.NET Framework is part of the .NET platform, a
collection of technologies for building apps for Linux,
macOS, Windows, iOS, Android, and more.
What is .NET .NET apps can run on many operating systems, using
different implementations of .NET (.NET Framework,
Framework? .NET Core or .NET, and Xamarin/Mono).
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.
. NET Framework supports more than 60 programming
languages of which 11 programming languages are
designed and developed by Microsoft.
C#.NET
VB.NET
C++.NET
Eleven J#.NET
Programming F#.NET
Languages JSCRIPT.NET
developed by WINDOWS POWERSHELL
IRON RUBY
Microsoft
IRON PYTHON
C OMEGA
ASML(Abstract State Machine Language)
.NET is Cross-Platform and runs on Linux, macOS, and
Windows OS. .NET Framework only runs on Windows
What is the OS.
difference .NET is Open-Source and accepts contributions from
between .NET the community. The .NET Framework source code is
available but does not take direct contributions.
and .NET
.NET Framework is included in Windows and
Framework? automatically updated machine-wide by Windows
Update. .NET is shipped independently.
WinForms: This is used for developing Forms-based
applications, which would run on an end-user machine.
Notepad is an example of a client-based application.
ASP.NET (Active Server Pages): This is used for
developing web-based applications, which are made to
Applications run on any browser such as Edge, Chrome or Firefox.
ASP.NET is a web framework designed and developed
Developed by Microsoft.
using .NET ADO.NET (ActiveX Data Object): This technology is
Framework used to develop applications to interact with databases
such as Oracle or Microsoft SQL Server.
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.
LINQ (Language Integrated Query): It is a query
language, introduced in .NET 3.5 framework. It is used
to make the query for data sources with C# or Visual
Basics programming languages.
Applications Entity Framework: It is an ORM (Object Relational
Mapping)-based open-source framework that is used
Developed to work with a database using .NET objects. It
using .NET eliminates a lot of developers’ effort to handle the
database. (We learned Hibernate Framework in AJT).
Framework Parallel LINQ: Parallel LINQ or PLINQ is a parallel
implementation of LINQ to objects. It combines the
simplicity and readability of LINQ and provides the
power of parallel programming. Fast speed execution
of LINQ queries.
Architecture of
.NET
Framework
.NET applications are written in the C#, F#, or Visual
Basic programming language.
Code is compiled into a language-independent Common
Intermediate Language (CIL). Compiled code is stored in
assemblies—files with a .dll or .exe file extension. It is
Architecture of called as MSIL (assembly code).
.NET When an app runs, the CLR takes the assembly and uses
a just-in-time compiler (JIT) to turn it into machine code
Framework that can execute on the specific architecture of the
computer it is running on.
The Common Language Runtime (CLR) is the execution
engine that handles running applications. It provides
services like thread management, garbage collection,
type-safety, exception handling, and more.
Components
of .NET
Architecture
Common Language Specification (CLS) helps in easy creation of
the apps and software. Common Language Specification also
helps in reduction of cost. It helps in reducing the development
time and cost.
The Common Language Infrastructure (CLI) is an app
development framework that is language-independent.
Therefore, developers don’t have to worry about changing the
Components language or syntax of their source code when switching from
of .NET one platform to another.
Architecture Common Type Specification (CTS) is a language supporting
multiple data types is known as a common type system.
CLR
Framework Class Library (FCL) The FCL is part of the Common
Language Runtime. It is loaded when the program starts and
unloaded when the program ends. This loading and unloading
process is also known as “Dependency Injection”.
Interoperability – Migrating lower version application to
higher version is easy.
Portability – works on any windows platforms.
Security - inbuilt security mechanism helps in both
Advantages of validation and verification of applications.
.NET Memory management – CLR will take care.
Simplified deployment - The .Net framework also have
tools, which can be used to package applications built on
the .Net framework. These packages can then be
distributed to client machines.
Step 1: File > New Project > C# Class Library
using System;
namespace ClassLibrary1
{
public class Class1
A Demo on {
public string DisplayString(string GetString)
Language {
Interoperability string str = "Hi!! I am from C#.NET " + GetString;
return str;
}
}
}
Step 2: Right click on solution Class Library > Add > New Project > Visual Basic >
Windows Form App
A Demo on
Language
Interoperability Step 6: Right click on VB WinFormApp > select “set as startup project” >
build and run
// Create a simple LINQ query.
using System;
using System.Linq;
class SimpQuery {
static void Main() {
int[] nums = { 1, -2, 3, 0, -4, 5 };
class Program {
static void MyMethod() {
// code to be executed
}
}
static void MyMethod(string fname) {
Console.WriteLine(fname + " Welcome to MU");
}
static void Main(string[] args) {
C# Methods MyMethod("Ram");
Parameters
MyMethod("Sofi");
and
MyMethod("Aarav");
Arguments
}
When a parameter is passed to the method, it is called an
argument. So, from the example above: fname is a
parameter, while Ram, Sofi and Aarav are arguments.
Access modifiers are accessibility levels of types and type
members and set rules how a type and its members can be
used within the type, current assembly, and other assemblies.
Access
Scope
Modifier
student1.print();
Console.ReadLine(); Name: MU
} Hello from Student class
} }
using System;
namespace MyApplication1
{
class Student
{
private string name = "MU";
// derived class
class Program : Student
{
Protected static void Main(string[] args)
{
class Student
{
internal string name = "MU";
}
class Program
{
static void Main(string[] args)
Internal {
Internal Console.ReadLine();
}
namespace Assembly2
{
} // derived class of Greet
} class Program : Greet
{
static void Main(string[] args)
Output: {
Program greet = new Program();
Console.Write(greet.msg);
Hello Console.ReadLine();
}
} Output:
} Hello
using System;
namespace Assembly1
{
public class StudentName
{
private protected string name = "MU";
}
class Program1 : StudentName
{
static void Main(string[] args)
Private {
Program1 student = new Program1();
Protected // accessing name field from base class
Console.Write(student.name);
Console.ReadLine();
}
}
}
Output:
MU
Caller's location public protected protected internal private private
internal protected
Within the class ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Derived class
✔️ ✔️ ✔️ ✔️ ✔️ ❌
(same assembly)
Non-derived class
(different ✔️ ❌ ❌ ❌ ❌ ❌
assembly)
In C#, a constructor is similar to a method that is
invoked when an object of the class is created.
However, unlike methods, a constructor:
has the same name as that of the class
does not have any return type
C# class Car
{
Constructors // constructor
Car()
{
//code
}
}
Car car1 = new Car();
Types of Constructors
Parameterless Constructor
When we create a constructor without parameters, it is
known as a parameterless constructor.
Parameterized Constructor
In C#, a constructor can also accept parameters. It is
C# called a parameterized constructor
Constructors Default Constructor
If we have not defined a constructor in our class, then the
C# will automatically create a default constructor with an
empty code and no parameters
using System;
namespace Constructor
{
class Car
{
// parameterless constructor
Car()
{
Console.WriteLine("Parameterless Constructor");
Parameterless }
// call constructor
new Car();
Console.ReadLine();
}
}
} Output: Parameterless Constructor
namespace Constructor
{
class Car
{
string brand;
int price;
// parameterized constructor
Car(string theBrand, int thePrice)
{
class Program
{
int a;
}
}
}
Default value of a: 0
A copy constructor is used to create an object by copying data
from another object
namespace Constructor
{
class Car
{
string brand;
Car(string theBrand)
{
brand = theBrand;
}
Copy // copy constructor
Car(Car c1)
Constructor {
brand = c1.brand;
}
static void Main(string[] args)
{
// call constructor
Car car1 = new Car("BMW");
Console.WriteLine("Brand of car1: " + car1.brand);
// call the copy constructor
Car car2 = new Car(car1);
Console.WriteLine("Brand of car2: " + car2.brand);
Console.ReadLine(); Brand of car1: BMW
} } } Brand of car2: BMW
A private constructor can be created using the private
access specifier. This is known as a private constructor
Private in C#.
Constructor
Once the constructor is declared private, we cannot
create objects of the class in other classes.
The static constructor is called only once during the execution of
the program.
We can have only one static constructor in a class.
It cannot have any parameters or access modifiers.
namespace Constructor
{
class Car
{ // static constructor
static Car()
Static {
Console.WriteLine("Static Constructor");
Constructor }
// parameterless constructor
Car()
{
Console.WriteLine("Default Constructor");
}
static void Main(string[] args)
{
// call parameterless constructor
Car car1 = new Car();
// call parameterless constructor again Static Constructor
Car car2 = new Car(); Default Constructor
Console.ReadLine(); } } } Default Constructor
Data abstraction is the process of hiding certain details and
showing only essential information to the user.
Abstraction can be achieved with either abstract classes or
interfaces.
Abstract class cannot be instantiated.
Abstract methods have the following features:
An abstract method is implicitly a virtual method.
Abstract Class Abstract method declarations are only permitted in abstract
classes.
Because an abstract method declaration provides no actual
implementation, there is no method body; the method
declaration simply ends with a semicolon and there are no curly
braces ({ }) following the signature.
For example:
public abstract void Semester();
// Abstract class
abstract class MU
{ public int a = 10;
// Abstract method (does not have a body)
public abstract void Semester();
// Regular method
public void sleep()
{
Console.WriteLine("Zzz");
}}
class Program{
static void Main(string[] args)
{ MU m = new UG();
m.Semester();
m.sleep(); I am from UG
}} Zzz
In C#, an interface is similar to abstract class. However, unlike
abstract classes, all methods of an interface are fully abstract
(method without body).
We use the interface keyword to create an interface.
We cannot use access modifiers inside an interface.
All members of an interface are public by default.
Interface An interface doesn't allow fields.
Syntax:
interface InterfaceName
{
// method without body
void calculateArea();
}
// Interface
interface MU
{
//int a = 10;
void Semester();
}
interface Results
{
void Grade();
}
class Student : MU, Results
{
public void Semester(){
Interface }
Console.WriteLine("Exam");
class D : A
{
public override void e()
{
Base Keyword base.e();
inside method Console.WriteLine("D"); }
class Program
}
{
static void Main(string[] args)
{
D d = new D();
d.e();
}
}
}
using System;
public class Animal {
public string color = "white";
}
public class Dog : Animal {
string color = "black";
Base Keyword public void showColor() {
to refer Console.WriteLine(base.color);
variable Console.WriteLine(color);
} }
public class TestBase {
public static void Main() {
Dog d = new Dog();
white
d.showColor();
black
} }
using System;
public class Animal {
public Animal()
{
Console.WriteLine("animal"); } }
public class Dog : Animal {
public Dog() {
Base Class Console.WriteLine("dog"); } }
Constructor public class TestOverriding
{
public static void Main()
{
Dog d = new Dog();
animal
}
dog
}
Polymorphism simply means occurring in more than
one form.
That is, the same entity (method or operator or object)
can perform different operations in different scenarios.
Polymorphism
There are two types of polymorphism:
Compile Time Polymorphism / Static Polymorphism
Run-Time Polymorphism / Dynamic Polymorphism
In compile time polymorphism, the compiler identifies
which method is being called at the compile time.
Compile Time In C#, we achieve compile time polymorphism through
2 ways:
Polymorphism
Method overloading
Operator overloading
using System;
class Program
{
// method adds two integer numbers
void totalSum(int a, int b)
{
Console.WriteLine("The sum of numbers is " + (a + b));
}
class D : A
Method {
public override void e()
Overriding {
Console.WriteLine(" D");
} }
class Program{
static void Main(string[] args)
{
A a = new A();
a.e();
D d = new D();
d.e(); A
D
} } }
using System;
namespace SealedClass
{
sealed class Animal
{
}
// Error Code
class Dog : Animal
{
Sealed }