Module 1
Module 1
Department of MCA
Handling By
Nirupama K
Asst. Prof. Dept. of MCA
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
What is .NET ?
Microsoft.NET is a Framework
• Microsoft .NET is a Framework which provides a common
platform to Execute or, Run the applications developed in
various programming languages.
2
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Evolution of .NET
• Mid ninety Java was most popular because of platform independent and
open source from Sun Microsoft
• In the year 2002 new edition of Java J2EE
• Microsoft released the first version of .NET with the name .NET
framework 1.0 Feb 2002
• To release 2nd version they took one year that version is known as Visual
Studio NET 2003
• Next release in the year 2005
• In the year 2008 NET 3.5 is released
• In the year 2010 NET 4.0 is released
04/04/2024 3
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Introduction
• NET framework is an essential component of window operating system
• Programming languages C#, J#, VB and Visual C++
• 3 important components CRL, CLS, CTS
• NET framework is a bridge between applications which are created using
C#, Visual Basic
• Evolution
o Mid 90s java was popular to develop the application
o 2002 J2EE introduced
o February 10 2002 .Net framework 1.0 released along with visual
studio IDE
04/04/2024 4
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
.NET Framework Objectives
5
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Benefits of .NET Framework
• Consistent Programming Model- Provides a consistent object-oriented
programming model across different languages.
• Cross-platform support- specifies that any window platform that
support CLR can execute .NET application, that is, .NET application
enables interoperability between multiple windows operating system.
• Language Interoperability- Enable code written in different language to
interact with each other .
• Automatic Management of Resources- Specifies that in .NET you do not
need to manually free the application resources, such as files, memory,
network and database connection.
• Ease of deployment - specifies that the .NET framework install
applications or components that do not effect the existing application
04/04/2024 6
. BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
NET Framework
Windows
ASP.NET ADO.NET
Forms
Operating System
. BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
04/04/2024 8
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
The Components of .NET Framework :
• Most important component of .NET framework
• Memory management, exception handling, debugging, security, thread
execution
• Managed code- executes directly by the CLR- selecting language
compiler, compiling the code to IL, compiling IL to native mode, execute
the code
• CLR also support for various resources such as collections, arrays,
operating system folder
• Runtime automatically releases the object when they are no longer in
use
• Unmanaged code
Common Type Specification (CTS)
• CTS specifies certain guidelines for declaring, using and managing types
at runtime
• Helps in cross language specification
04/04/2024 9
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Common Language Runtime (CLR)
• Most important component of .NET framework
• Memory management, exception handling, debugging, security, thread
execution
• Managed code- executes directly by the CLR- selecting language
compiler, compiling the code to IL, compiling IL to native mode, execute
the code
• CLR also support for various resources such as collections, arrays,
operating system folder
• Runtime automatically releases the object when they are no longer in
use
Managed Code
• Managed code is directly executed by CLR this code is automatically
have CLR services such as type checking, security and automatic garbage
collection.
• CLR complies the application to intermediate language and not machine
code
04/04/2024 10
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Unmanaged code
• It can directly compile to the machine code and runs on the machine
where it has been compiled
• This code does not have services such as security, memory management
Memory Management
• One of the most important service provided by CLR during managed
execution, automatic memory management
• CLR uses garbage collector to manage the allocation and release the
memory for an application
• Automatic memory management removes common problem such as
forgetting to free an object which results in memory leak
Common type specification (CTS)
CTS specifies certain guidelines for declaring, using and managing types at
runtime
Helps in cross language specification
04/04/2024 11
• Vccbvcb
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
• Support Object oriented model for implementation of different
programming languages
• Support primitive data types
04/04/2024 12
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Common Language Specification
CLS performs the following functions:
• Establishes a framework that helps enable cross-language integration,
type safety, and high performance code execution
• Provides an object-oriented model that supports the complete
implementation of many programming languages
• Defines rules that languages must follow, which helps ensure that
objects written in different languages can interact with each other
04/04/2024 13
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Assembly Contents : It has 4 elements they are as follows
• Assembly Manifest: Contains data that describe how elements are
related to each other within the assembly
• Global Assembly Cache(GAC):
• Strong Name Assembly:
• Private and Shared assembly:
• Side-by-side Execution Assembly:
• .NET Framework Class Library:
• Windows Form:
• ASP .NET and ASP .NET AJAX:
• ADO .NET:
04/04/2024 14
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Workflow Foundation (WWF)
• Activities
• Workflow designer
• Workflow Runtime
• Rules Engine
04/04/2024 15
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Presentation Foundation (WPF)
04/04/2024 16
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Communication Foundation
(WCF)
04/04/2024 17
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Exploring the features of Net Framework
• Improvement in the application compatibility and deployment
• Dynamic language runtime
• Managed extensibility framework
• Parallel computing
• Improved security model
• Networking improvement
• Improvement in WPF
• Improved entity framework
• Integration of WCF and WF
• Improved code ASP .NET services
04/04/2024 18
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Introduction to C# (C Sharp)
• Microsoft C# (pronounced C Sharp) developed by Microsoft
Corporation, USA
• New programming language that runs on the .NET Framework
• C# is simple, modern, type safe, and object oriented
• C# code is compiled as managed code
• Combines the best features of Visual Basic, C++ and Java
19
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
C# Features
• Type-Simple
• Modern
• Object-Oriented
• Versionable
• Compatible
• Secure
20
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Sample Hello world program
04/04/2024 21
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Basics of C#
• Identifier
• Keywords
• Operators
• Variables
• Literal
• Constant
• Expressions
• Declaring statement
• Executable statement
04/04/2024 22
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Creating console application
• Understanding System namespace
• Data types
• Boolean
Byte
Char
Date
Decimal
Double
Integer
Long
Object
• Declaring variable and constant
04/04/2024 23
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Most commonly used namespace
• using System;
• using System.Collections.Generic;
• using System.Data;
• using System.Drawing;
• using System.Linq;
• using System.Text;
• using System.Windows.Forms;
• using System.Data.SqlClient;
04/04/2024 24
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
04/04/2024 25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
04/04/2024 26
#
Introduction to C
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Prerequisites
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Learning Objectives
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Hello World
using System;
class Hello {
static void Main( ) {
Console.WriteLine("Hello world");
Console.ReadLine(); // Hit enter to finish
}
}
BMS
Agenda INSTITUTE OF TECHNOLOGY AND MANAGEMENT
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
The Big Ideas
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Component-Orientation
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Component-Orientation
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Everything is an Object
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Robust and Durable Software
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Preserving Your Investment
BMS
Agenda INSTITUTE OF TECHNOLOGY AND MANAGEMENT
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Overview
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Overview
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Overview
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Unified Type System
• Value types
• Primitives int i; float x;
• Enums enum State { Off, On }
• Structs struct Point {int x,y;}
• Reference types
• Root object
• String string
• Classes class Foo: Bar, IFoo {...}
• Interfaces interface IFoo: IBar {...}
• Arrays string[] a = new string[10];
• Delegatesdelegate void Empty();
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Unified Type System
int x = 123456;
long y = x; // implicit
short z = (short)x; // explicit
double d = 1.2345678901234;
float f = (float)d; // explicit
long l = (long)d; // explicit
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Object
o b ject
void Poly(object o) {
Console.WriteLine(o.ToString());
}
Poly(42);
Poly(“abcd”);
Poly(12.345678901234m);
Poly(new Point(23,45));
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Hint
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Boxing and Unboxing
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Boxing and unboxing
i 123
int i = 123;
object o = i; o System.Int32
123
int j = (int)o;
j 123
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Benefits of boxing
• Enables polymorphism across all types
• Collection classes work with all types
• Eliminates need for wrapper classes
• Replaces OLE Automation's Variant
• Lots of examples in .NET Framework
using System;
namespace lab project
{
class program2
{
/* C# program -Boxing and Un Boxing */
Predefined Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Value
Types
Character char
Logical bool
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Integral Types
C# Type System Type Size (bytes) Signed?
sbyte System.Sbyte 1 Yes
short System.Int16 2 Yes
int System.Int32 4 Yes
long System.Int64 8 Yes
byte System.Byte 1 No
ushort System.UInt16 2 No
uint System.UInt32 4 No
ulong System.UInt64 8 No
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Floating Point Types
decimal System.Decimal 16
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
decimal
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Integral Literals
123 // Decimal
0x7B // Hexadecimal
123U // Unsigned
123ul // Unsigned long
123L // Long
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Real Literals
123f // Float
123D // Double
123.456m // Decimal
1.23e2f // Float
12.3E1M // Decimal
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
bool
string s2 = @“\\server\fileshare\filename.cs”;
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
User-defined Types
Enumerations enum
Interface interface
Enums
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types
Enums
Color c = Color.Black;
Console.WriteLine(c); // 0
Console.WriteLine(c.Format()); // Black
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Enums
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Arrays
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Arrays
• Declare
int[] primes;
• Allocate
int[] primes = new int[9];
• Initialize
int[] prime = new int[] {1,2,3,5,7,11,13,17,19};
int[] prime = {1,2,3,5,7,11,13,17,19};
Arrays
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Interfaces
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Classes
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Classes
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Structs
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types
Classes and Structs
10
sp
20
cp CPoint
10
20
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Delegates
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Overview
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types
Assembly
Module
File
Type
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
namespace N1 { // N1
class C1 { // N1.C1
class C2 { // N1.C1.C2
}
}
namespace N2 { // N1.N2
class C2 { // N1.N2.C2
}
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
using N1;
C2 c; // Error! C2 is undefined
N1.N2.C2 d; // One of the C2 classes
C1.C2 e; // The other one
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
using C1 = N1.N2.C1;
using N2 = N1.N2;
C1 a; // Refers to N1.N2.C1
N2.C1 b; // Refers to N1.N2.C1
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
References
void Foo() {
i == 1; // error
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Overview
int a;
int b = 2, c = 3;
a = 1;
Console.WriteLine(a + b + c);
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables and Constants
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables and Constants
{
int x;
{
int x; // Error: can’t hide variable x
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables
void Foo() {
string s;
Console.WriteLine(s); // Error
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Labeled Statements & goto
int i = 0;
while (i < 5) {
...
i++;
} int i = 0;
do {
...
i++;
}
while (i < 5);
while (true) {
...
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
for Statement
try {
Console.WriteLine("try");
throw new Exception(“message”);
}
catch (ArgumentNullException e) {
Console.WriteLine(“caught null argument");
}
catch {
Console.WriteLine("catch");
}
finally {
Console.WriteLine("finally");
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Synchronization
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Synchronization
public class CheckingAccount {
decimal balance;
public void Deposit(decimal amount) {
lock (this) {
balance += amount;
}
}
public void Withdraw(decimal amount) {
lock (this) {
balance -= amount;
}
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement
Category Operators
Grouping: (x)
Member access: x.y
Method call: f(x)
Indexing: a[x]
Post-increment: x++
Primary
Post-decrement: x—
Constructor call: new
Type retrieval: typeof
Arithmetic check on: checked
Arithmetic check off: unchecked
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence
Category Operators
Positive value of: +
Negative value of: -
Not: !
Unary Bitwise complement: ~
Pre-increment: ++x
Post-decrement: --x
Type cast: (T)x
Multiply: *
Multiplicative Divide: /
Division remainder: %
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence
Category Operators
Add: +
Additive
Subtract: -
Shift bits left: <<
Shift
Shift bits right: >>
Category Operators
Equals: ==
Equality
Not equals: !=
Bitwise AND &
Bitwise XOR ^
Bitwise OR |
Logical OR ||
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence
Category Operators
Ternary conditional ?: