Adobe Scan 21 Jun 2024
Adobe Scan 21 Jun 2024
CHAPTER
Syllabus
Types, Objects, and Namespaces:The Basics About Classes, Buildinga Basic Class
Value Types and Reference Types, Understanding Namespaces and Assemblies.
Advanced Class Programming.
1. Classes
It is user define data type and it is only a logical representation of data. It helps to
link member variables and methods.
2. Objects
These are basically instance of a class. It is basically representation of real time
entity.
Concepts
The three main concepts of object oriented programming are :
1. Encapsulation
2. Abstraction
3. Polymorphism
P 2.2 ’ Encapsulation 1.
’
the Methods
Methods changed.
properties,
methods
Unlike SomePropertiesClasses
Properties E.g.
anotheroperation. It 3.
information helps It 2. object. dataclass) Adv.
object's is Abstraction gives It helps property
Encapsulation Wrapping
Classes one
additionPolymorphism Abstraction Web
properties to related is
allow interact appended name a
focus to toHide called
helps generalized Prog.
state of of is represent access to up
you and on
anthe the a (MU
to with two is an
Encapsulation.
ificantly. object what a
the data object data
to
may access
Syllabus string.
numeric different process B.Sc.
each the technique
perform be view the private for
Extensively in cssential into member IT
read-only, an other an object security -
thatare object's values forms. of of data that Sem-V)
Topic understandablehiding your used Itand
with object. is
performused actionan
The
doesfeature that
for a the :The classes such to like a
sodata. usedresults the instead wil protect method
help behaviour 2-2
distinct
actions on they Basics when be
as capsule a
an in working orwithout
of manner. objects of public.making the together
object. cannot three sum, a how
implementing
About depends representing that
and style information
the
be key bydoes it encloses into
Classes addition of variables
modified, ingredients: on providing a Types,
an it.
inheritance. the the in thsingle
e
of type
object, CxpOse an
private,and relatcd Objects
background
relevant wo
uni(tin
while two objcct
task of and and
strings data
others fromoperation.otlher NamoSp
or used
showine
informas:. detail.s anot,
may m prod
can ins
numb
Class MyClass
class 2.2.1 Events G
public
put)
void
2.2.1
Ex.
member variables Class Public access
In accessible them. to Bymethods; ll body A A Events Adv.
public
get)
void xy;int
order
definition
starts
class class
default, members.
Class / { Defininga
class Web
comprises enclosed
keyword in provide
function
public.as to can Prog.
to classes defined
implement only code (MU
by notification
of can a
accessed are pair in B.Sc.
member other in
bedeclared
c# Syllabus
ofwith by IT
encapsulation projects. used -
by curly keywordusingthe that Sem-V)
variables the
member to Topic
something
as braces.
keyword
specify internal,
and Building :
functions.
member 2-3
member that class has
i.e.
class. happened.
the only followed a
variables
functions class It Basic
code is
in
is byuser a Class
are i.e. public the the Types,
defined
class
declared methods. current Objects
and name; type.
data
project and
as These should
private and Name
member have
will the
also
Spaces
and class
be
2-4 Types, Objects and Name
Adv. Web Prog. (MU B.Sc. IT - Sem-V)
Spacen
2.2.2 Adding Propertles
If we declare a member as private it is not accessible outside. In order to achieve this We
have to declare property accessor. Accessors usually have two parts. The get acCessor
allows your code to retrieve data from the object.
cases, you might .
The set accessor allows your code to set the object's data. In some
one of these parts, such as when you want to create a property that can be examined 1but
not modified.
Ex. 2.2.2
Class numb
{ public int x;
public int y;
public int x
{
get{
retun X;
set
{
X=value;
public int y
getí
retun y;
Set
y=value;
Adv. Web Prog. (MUB.Sc. IT- Sem-V) 2-5 Types, Objects and Nanme Spaces
When we create an object we can access the property directly.
numb n = new num);
n.x = 10;// calls Set
n.y = 12;/l cals Set
2.2.3 Constructor
int x,y;
public numb)
A default constructor does not have any parameter but if you need, a constructor can
have parameters. Such constructors are called parameterized constructors.
This technique helps you to assign initial value to an object at the time of its creation
2.2.4 C# Destructors
int x,y:
public numb)
}
publicvoid put)
{
}
{
numb n=new numb0; //object is created
D.get);
n.put0:
}
The Types in .NET Framework are either treated by Value Type or by Reference Type. A
Value Type holds the data within its own memory allocation and a Reference Type
contains a pointer to another memory location that holds the real data.
Reference Type variables are stored in the heap while Value Type variables are stored in
the stack.
Stack Heap
Value Types
Reference Types
Pointers to the
Reference Type
Fig. 2.3.1
P Value Type
A Value Type stores its contents in memory allocated on the stack. When you created a
Value Type, a single space in memory is allocated to store the value and that variable
directly holds a value.
If you assign it toanother variable, the value is copied directly and both variables work
independently. Predefineddata types, structures, enums are also value types, and work in
the same way.
Value types can be created at compile time and Stored in stack memory, because of this,
Garbage collector can't access the stack.
E.g
int y = 56;
Reference Type
Reference Types are used by a reference which holds a reference (address) to the object
but not the object itself. Because reference types represent the address of the variable
rather than the data itself, assigning a reference variable to another doesn't copy the data.
Instead it creates a second copy of the reference, which refers to the same location of the
heap as the original value.
T Adv. Wob Prog. (MU B.Sc. IT - Sem-V) 2-8 Types, Objects and
Name Spa,
Reference Type variables are stored in a different arca of memory called the
means that when a reference type variable is no longer uscd, it can be marked heap. Th
for
collection. Examples of reference types are Classes, Objects, Arrays, Indexers, garta
C.g.
etc.
Interfac
int|] a = new int|20]:
In the above code the space required for the 20 integers that make up the array is
on the heap.
allocae,
Syllabus Topic : Understanding Namespace and Assemblies
2.4
Namespace
Anamespace is designed for providing a way to keep one set of names separate
another. The class names declared in one namespace does not froa
conflict with the same ol
names declared in another.
T Defining a Namespace
A namespace definition begins with the keyword
namespace followed by the namesar:
name as follows:
namespace namespace name {
ll code declaration
To call the
namespace-enabled version of either function or variable, add the namespa:
name as follows
namespace name.item name;
G The using Keyword
The using keyword states that the
For examnple, we are using the program is using the names in the given namespa
System namespace in our programs.
Adv. Web Prog. (MU B.Sc. IT-Sem-V) 2-9 Types, Objects and Name Spaces
E.g.
using System :
2.4.1 Assembly
An assembly is a fundamental building block of any NET framework application. It
contains the code that is executed by common language runtime.
For example, when you build a simple C# application, Visual Studio creates an assembly
in the form of a single portable executable (PE) file, specifically an EXE or DLL. Every
assembly has a file called 'manifest' file that stores all information about that assembly.
These informations are known as metadata. The manifest file contains all the metadata
necded to specify the assembly's version requirements, security identity, and all metadata
needed to define the scope of the assembly and resolve references to resources and
classes.
An assembly can be a single file or it may consist of the multiple files. In case of multi
file, there is one master module containing the manifest while other assemblies exist as
non-manifest modules.
Components ofAssembly
1.Private assemblies
2.Shared assemblies
Fig. 2.4.1
1. Private assemblies
Normally used by a Singleapplication, and stored in the application's directory.
language-specific resources for an application.
Often used to deploy
2. Shared assemblies
global assembly cache, which is a repository of
Normally stored in the
assemblies maintained by .NET.
assemblies within the same application, the same copy of the
For all the calling
original location.
shared assembly is used from its
Programming
Syllabus Toplc :Advanced Class
2.5 Advanced c# programming
2.5.1 Inheritance
Types
Single inheritance
Multiple inheritance
Hierarchical inheritance
Multilevel inheritance
Defining a subclass
class subclass_name : baseclass_ name
variable declaration;
method declaration;
Adv. Web Prog. (MU B.Sc. IT- Sem-V) 2-11 Types,Objects and Name Spaces
G Ex. 2.5.1
Class room
return(length breadth);
int height;
public rooml(int x, int y, int z) : base (x, y)
2.5.2 protected pablic
Declaring
ItInterfaces {
Interfaces are providing Interfaces ItInterfacesInterface
inheritance
implement
multiple doesC#
is is partial rum volume)
Nablieint Acv.
similar the Multiple void Web
class (length height ;
responsibility containdefine int int rooml Page
to standard a supportnot Response.Response. voll areal
Prog.
usingthe
classdeclared Load(object Defaul1
properties,
Inheritance breadth (MU
only = = rl=
declaration. structure Write("Vol
Write("Area
rl.volume():rl.area); new
: B.Sc.
of the System.Web.UL.Page *
multiple rooml sender, height); IT
declaration
the methods,
hat
tderiving in ="="+ superclass // Sem-V) -
//method (10, EventArgs
Interface
keyword.
interface C# + subelass
the 20,
inheritance. voll); areal):
15);
deriving of and
he method e) 2-12
statements class tevents,
members.
classes to
define which However,
are
public would
the are
follow.
members. the youcan Types,
by members
default. Objots
It interfacesuse
often of
the
help intert