Professional Documents
Culture Documents
Adobe Scan 19 Jun 2024
Adobe Scan 19 Jun 2024
Adobe Scan 19 Jun 2024
CHAPTER
Introducing .Net
Syllabus
Introducing .NET : The NET Framework, C#, VB, and the NET, Languages, The
Common Language Runtime, The .NET Class Library.
The C# Language: C# Language Basics, Variables and Data Types, Variable
Operations, Object-Based Manipulation, Conditional Logic, Loops, Methods.
Sylabus Topic : The .NET Language and The Common Language Run Time(CLR)
1.1.1 The Common Language Run Time (CLR)
It is the foundation of the .NET Framework. It helps to manage the code during execution.
Considered as the heart of .net frame work.
It manages memory, thread execution, code execution, code safety verification.
compilation and system services.
Adv. Web Prog. (MU B.Sc. IT- Sem-V) 1-2 Introducing .Ng
c. Garbage Collector
Fig. 1.1.1
ASP.NET
Web Foms, XML Web Services Windows Foms Console
Operating System
Fig. 1.1.2
The binary information describing the program, which is cither stored in a portable
executable file (PE)or in the memory.
Assembly is a logical unit consisting of the assembly manifest, type mctadata, lL code
and a set of resources like image files.
Adv. Web Prog. (MU B.Sc. IT- Sem-V) 1-4 Introducing Net Introducing .Net
Adv. Web Prog. (MU B.Sc. IT -Sem-V) 1-5
Introduction to C# predefined reserved words that have special meaning to the compiler.
1.2
They cannot be used as identifiers in programs unless they are prefixed with @.
Simple, modern, object-oriented and type-safe language. Contains new features like Ex: @for can be used as an identifier.
delegate, indexers, properties etc.
lobany
It is part of a suite of products called Visual Studio .NET.
G Constants & Variables
for- cannot be used as an identifier since it is a reserved word
NOT !A
Decrements the value by
Returns false it operand is true or true otherwise.
decreases the value by I and stores it back in a
+ 2. Comparison or Relational Operator Note: "Unary operator
Itis used to compare values. It returns a Boolean value either True or false, this operato 4. Assignment operator
also comes under the binary opcrators category. It is classified into two types :
The following table describes the list of comparison operators: (i) Simple and Assignment
Operators Deseription Example (ü) Compound assignment operator.
Equal to A==b
Returns true if both the values are same, false otherwise. The main function of this operators is used to assign values.
(0) Simple Assignment
Not equal to A!=b
"=" isthe operator which is used to assign value to a variable.
Returns true if both the values are different, false other
wise Example
V Less than S<b
c=a+b;
(i) Compound Assignment
Returns true if the value of S is less compared o b
This operator is basically a combination of simple assignment operator and the othe
Greater than S>m
operators. We can use this operator only when the variable used in left hand side is also ther
Returns true if s>m clse false. in the right hand side.
Less than cqualto g<=y Operator Deseription Example
Returns true if g is less than or cqual to y t=,=,"=J=,%= Performs addition and a+=5 ie a=a+5
Greater than equal k>p assignment respectively. Increase the value of a
Returns true if k is bigger or equal to p otherwise false Same with other operators by 5 and stores back in a.
’ 3. Loglcal operators ’ 5. Conditlonal operator
This operator too is used with conditional statements. It returns This operator comes under the category of ternary operator, since it takes three operan
either true or false. The
lollowing are the list of operators : It is represcnted as ?: the expression is evaluated to true or false depending on
value any of the given two statements is executed.
Adv. Web Prog. (MU B.SC. IT - Sem-V) 1-10 Introducing Adv. Wetb Prog. (MU B.Sc. IT - Sem-V) 1-11 Introducing .Net
Example To
FROM
c={ a>b ?a:b): long, float, double, decimal
Int
In the abOve statement c is assigncd a if a>b otherwise b. Uint long, ulong, float, double, decimal
1.3.1 Bitwise Operator Long float, double, decimal
Allow evaluation and manipulation of specific bits within an integer. ulong float, double, decimal
Bitwise operation operates on one or more bit patterns or binary numerals at the Float double
individual bit level. Char ushort, int, uint, long, ulong. float, double, decimal
Primitive action directly supported by the processor.
& - bitwise AND
(ii) Explicit Conversion
Converting from a larger data type to smaller data type is called Explicit type conversion.
I- bitwise OR
A- bitwise exclusive OR For example converting from float to int, double to float etc. In this conversion there is a
chance of loss in data.
>>- shift ight
Explicit type conversion is done in c# by using methods defined in Convert class.
<<- shift left
Command Result
-- one's compliment
1.3.2 Type Casting Convert.ToBoolean(x) Xis converted to Boolean
It is necessary to convert data from one type to another can be achieved through type Convert.ToByte X converted to byte
casting. Convert.ToChar(x) X converted to char
There could be a possibility of loss of data when larger data types are cast onto Convert.ToDecimal(x)X converted to decimal
smaller
data types.
Convert.ToDouble(x) Xconverted to double
(i) Implicit Conversion
(ü) Explicit Conversion Convert.Tolnt16(x) X converted to short
e.g.
’ () Implicit conversions
int n=Convert. Tolnt16("12");
Conversions where there is no loss of data.
Will convert string to int.
Conversion always from smaller data types to larger data types.
Ex. :a short can be implicitly
converted to int- short is a Syllabus Toplc :0bect Based Manipulation
subset of int.
FROM To 1.4 Object Based Manipulation
Sbyte Short, int, long, float, double, decimal
Byte .NET is object-oriented to the core. Common data types have the built-in smarts to handle
Short, ushort, int, uint, long, ulong, float,
Short double, decimal basic operations (such as counting the number of characters in a string).
int, long, float, double, decimal
Ushort We can manipulate strings, dates, and numbers in the same way in C#.
int, uint, long, ulong, float,
double, decimal
’ Members
String o String 1.
’
specificExtract These The 2. This substring. portion
Split)- IndexOf)StartsWith) Replace)-
Remove)- Insert()specify. PadLeft) as Trim0,
(or uppercase
ToUpper()Length- The s= s s=strinExample g with Tone Adv.
DateTime The returns many both) =s. S
s.ToUpper);
above ubstring(0,
s.Trim): s strings.
presentation a
class Divides of -Inserts TrimEnd), = of Web
part DateTime times ends Returns the
members only and Replaces
and string
aRemoves and
lowercase
or and statements "Asp.Net Prog.
and LastindexOf()- PadRight(0- of // We best
of a
string the EndsWith)- another necessary as
a ToLower) the / = 3); OP uase
(MUB.SC.
a
TimeSpan of string. and
DateTime allow
(such
and first the a a number use "ASP" "ASp. //Net C# exampl e
specified OP functions
TimeSpan into match specified
specified string TrimStart()- characters.
-Returns built-in Programming IT-
as you an Adds
to of "Asp" of Sem-V)
the (for todata array and FindsDetermines inside make C#
number the
characters
methods,such as for how
total
example, perform types
Types of can the
length
substring
a specified the Removes a Programming" manipulation "; class
number string copy
also substrings start total
zero-based whether the at stringsof 1-12
just
three have
at with at length of thein members
of the specified a character spaces the
days the usefulbuilt-in delimited end another specified string
string of
a from Substring(),
ToUpper/)
Trim), can
year) position string of or strings.
or tasks: or a th e (as
total methods beginning. location specified
(zero-based)
to some with
an replace
or by starts string. string the
number a of appropriate other integer).
all
convert
and
specific or
a Substring)- (as equal th e built-in
substring ends aposition. characters characters
of properties.
a new index to
minules) substring with th e side functions
TimeSpan in
string).
a Extractsi position. number of from
Introducing
a specitia chanos
suly a
to wstri eii
’
Clear)- of Array
GetUpperBound)
array.Length
an GetLength) findArrays TotalMinutes, 3.
TotalDays, members
Add) Days, Time Add) Now-Givesmembers
span integer. Year,Today-Gives Tlme
date DateTime.Now;
e.AddDays(100); Determine Easily Adv.
s= e= Examplewhether
stringDateTimee=
GetLowerBound), n=int]
out Array TypeThe Web
membersmyArray.Length; myAray and Hours, Date, and perform
clears Returns
- the also Second, the Prog.
method, sizebehave TotalHours- Minutes,
Subtract) Subtract)- e.Year.ToString0;
Month, the dat e the
TotalSeconds, current
datandecurrent current date (MU
the = and
an method {1,2 , of occurs
anray B.3c.
GetUpperBound) integer
// both alike Combines Millisecond Day, Adds calculations.
ofp 3,4, of objects Seconds- indate
one-dimensional date
IT-
to Returns Hour, a
that find =5 5); which number or and leap and Sem-V)
subtracts sets
represents in t in TimeSpan Returns Minute- time
year). time
the tim e
retun
n; the of the and
-and highest
new days, a to
thearray, totalobjects one Returns
TimeSpan00:00:00 other 1-13
Determines the world
index total component
hours,
total you value information
number number of together. one
number can NET. minutes, from
the of part
use of
dimensions
of in of the the of the (such
an clements the For and DateTime.
the
elements array. example, current current
Length so DateTime as
on. the
of in TimeSpan.
an in property
an TimeSpan day
array. all if
aray you object of Introducing
.Net
dimensions the
theorwant as as weck
to a an
or
Adv. Web Prog. (MU B.Sc. IT- Sem-V)
Generally a program is executed sequentially one after another but there might L
situations where the statements need to be executed only based on some condition.
Java script supports two types of statements : Control Flow Statement
1. Selection statements.
2. Looping statements. 1. Selection statements
a. if statement
’ 1. Selection statements
b. if-else statement
The statements are executed only if the conditionis
satisfied. We have three types of selection c. if-elseif statement
statements :
d. switch case
(a) if statement
2. Loopingg statements
(b) if-else statement
a. while
(c) if-elseif statement.
(d) switch case. b. do -while
Fig. 1.5.2
Statement,
Console Write("aitive"
+ (b) I-clse statenent
This statenent is similar to if statement but the only differene is different set of
Ntatenments are ereouted based on the condition whether it is true or false.
The lowchart clescribes its working :
Ya
ondltlon Statement
|No
Satement
8yntax
expreaion)
Satenenta)
elae
Satementa
Statement-3;
executed. statements
bewil
case the omitted
al statement
if , case switch the fromterminate statement
wil break elseif(expresion3)
statement(s): default:
} Statement-2;}
break; (expression2) elseif
statement(s); condition
n: case
Statement-l;
break;
iflexpressionl){
statement(s); condition
2: case
break; Syntax
statement(s); condition
l: case 1.5.4 Fig.
End)
(expression) switch Statement
Syntax No
used. be
condition
wil default matches,a nothing found.
If Statement Condition
match
is expression
untail the of
value thagainst
e case each checksinterpreter The
expression. the value
of the on
based execute No
atements
to different several andevaluate expression
to an
give statement
to is Switch Condition
Statement
case switch (d) ’ Yes
>"): Write("cis Response. below The working. tdepicts
he figure
used, multiple check tohave When
we
else statement
becan ifconditions
if-else
>"); Write("bis Response. statement if-elseif (c) ’
(b>a)&&(b>c)) Elseif
Wite("Negative"; Response.
>"); Write("a
is Response.
&&{a>c)) (a>b) if
else
Example r
rie"Psitive": Response.
Statement-4;
Introducing
.Net Sem-V) (MUB.Sc.
-IT Prog. Web Adv.
else \ntoducing Example s
1-17 Acv.
(MU Prog. Web
Sem-V) IT- B.Sc.
1-16
1-20
B.SC. IT- Sem-V)
Adv.Web Prog. (MU
Aow chart
\Introdudry Adv. Web Prog. (MU B.Sc. IT -Sem-V) 1-21
Introducing .Net
No
statements <condition
Yes Yes
no staternents
condition
End)
(End
Fig. 1.5.6
Fig. 1.5.7
o Syntax
Syntax
initislization;
lor(initialization; condition; increment/deerement)
ateme
statements;
hile(condiion);
Example
Exmple
for(i=1;i<=10;i++)
i=l;
Response. Write(i);
statement. Initialization,
condition and
foreach (array as value)
code to be executed;
Example
int[ arrl= {1,2, 3,4, 5}:
foreach (int x in arrl)
.Net
Introducing at syntax another typereturn be and the no required
has cannot
datathe pass of contain
program The
number
from to the
the then It may
structure. sensitive.usedand complete
Method method is values,
C# type method
Every are order,
its return to
ato a any case parameters
C# of or type,a needed
task. in Parameters 1.6.1
Fig. elements variable The returningis
value. is,
Methods the
aperform Methods List) it
Methods Steps
of and that instructions
Nane>(Parameter
<Method the to
DefiningPassingDelegates
3. the a not identifier refers
optional;
of areturn parentheses,
together declare is class.
:Topic visibility method list
1. 2.
1-23
follows: not the
unique parameter
are of
Main. basically set
that in
Syllabus the may the betweenParameters
declared the
IT-Sem-V) statements
named If a
determines or is
returns. name The contains
you as may
method
:to C# is Type>
Specifier>
<Return identifier
need in method,C#
method
method.
Enclosed method.
of Methods in method Method
B.Sc. method
Define
the method It This
groupawith we Call
the
method adefine Specifier: a
(MU Methods method, A : other :list from :
ais class Defining a :typethe name body
ofparameters
Prog. void.
is
type any data
method you defining value Parameter parameters.
activity.
Method
Web one a Method
Body Access Return Method
as receive
use When class. the same
Adv. least To for <Access of
A 1.
1.6 ’
Inttoduc
value
access define 0is elements
which
to to
isused value value, assigned. its
access
variahle
which
is constant
default
is to
type value indices
a a
array location.
memory
consecutive and assigned time
multiple
singleindex array, same
being commas:
ain an
with the the }; uses declaration.
1-22 initialize members at 99 that
stored and 10,2,
associated0. as
one declared more double[3,4|;
from declared
Sem-V) variables array (5,9, simply the
to 1.5.1.1
Mutidimensional
Arrays <baseType>L
<name>;
require
default int[5|;used
in
the array
be <baseType>|<name>;
IT- in <haseType>]<name>; is
array myIntAray is can
of array by value new explicitly all array dimensions new
BSC. niW
Response.
te(i}; lists in
the
=
starts below array of stdetails
(MU indexedthe variable. the mylntArray results multidimensional
in member int[] size
value store is two-dimensional
Proo Arrays clement keyword mehod numernc
types. example more the double[,]
Web are indexto of define
AravsEach belps oSyntax int] the Arrays
Adv The Eg, new size. This E.g. We
1.5.1 It In A
lntrexaing Net
AN Wahy (MU RSIT Sem
V)
Example
MIble int Num(int,in)
And st
’ 1 elegates
indireet calls to methods.
Dlegates are reterene vpes which allow by invoking
references to some number of methods, and
A delegate instance holds
methods to be called.
the delegate one causes all of these invoke them are
the fact that the functions which
The usefulness of delegates lies in
blind to the underlying methods.
function pointers.
functionally rather sinmilar to C++s
’ 2 Passing Parzmeters to a Method It can be scen that dclegates are differences.
two main
Whe metod i parzmes is callei. you need to pass the parameters to the However, it is important to bear in mind
than value types.
There re tre wzvs that perzeters can be passed to a metho:
method Fistly,delegates are reference types rather
methods.
Sr. Secondly, some single delegates can reference multiple
Mechanism &Description public delegate void Pointfunc
(String s):
contains the following method:
Value parameters Suppose, for instance, that a class
1.
The values re copied locally inside the function so any changes made inside the blie void deleMethod (String myng
function is not available outside.
I method code
Reference parameters
2 Sine the reference of the arguments is passed any changes
made inside is available instantiate the Print delegate in the following
OutSide too. Another method in this class could then
realMethod:
Output parameters way, so that it holds a reference to
3 SiCe tunction can only return one value and in a situation where we need to retur Print delerateVariable = new Pointunc(delemes
foore th2r one value this pararneter is used.
can simultaneously reference multiple
some delegates - termed multicast delegates
-specify a void return type.
methods. These delegates must - like our Pointfunc delegate
T Methods Over Loading
running of the method is the handling
C# supprts overloading We have the sarne furction name but The method invocation is termed an event, and the
perforning different user's selection of a button on a graphical
operations. of the event. An typical example of an event is a
of methods to handle it.
We can use sarne Tiarne to get different outputs. For exarnple surn) to add two intenet user inteface; this action may trigger a number
delegate.
rumber, decimal nurnber and concatenate two string. The event keyword is used to declare a particular multicast
Adv. Web Prog. (MU B.Sc. IT -Sem-V) 1-26
Introducing
else there js a
Multicast delegates must contain only methods that return void, run-i
exception
Each delegate has an invocation list
Methods are invoked sequentially, in the order added
respectively
The += and -= operators are used to add and remove delegates,
+= and -= operators are
thrcad-safe
delegate void mainEvent(int x, int y):
static void Funcl(int x, int y) {
Response. Write("lnfunction l"):
Review Questions