You are on page 1of 35

Module 2

Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit.
It is the mechanism that binds together code and the data it manipulates.
In a different way, encapsulation is a protective shield that prevents the
data from being accessed by the code outside this shield.

Technically in encapsulation, the variables or data of a class are hidden


from any other class and can be accessed only through any member
function of own class in which they are declared.
Program EX:
STATIC IN C#:
Ex;
There are 2 types of Static members:
Ex:
EX:
Ref and Out Keywords in C#:
Ex:
Enumeration in C#:
An enumeration is a set of named integer constants. An enumerated type
is declared using the enum keyword.

C# enumerations are value data type. In other words, enumeration


contains its own values and cannot inherit or cannot pass inheritance.

Declaring enum Variable


The general syntax for declaring an enumeration is −
enum <enum_name> {
enumeration list
};

Where,

• The enum_name specifies the enumeration type name.

• The enumeration list is a comma-separated list of identifiers.

Ex:
Struct and class in C#:
Structures in C#:

EX:
O/P:
Constructors in C#:
EX: (this can be used for default, parameterized and constructor overloading)
Copy Constructor:

Example:
Static Constructor:

Ex:
Private Constructor:

Ex:
Constructor Overloading:

//Same example can be used which was used for default and parameterized
constructors. Also check for all constructors in 1 program ex at end of pdf…

ARRAYS IN C#:
Assigning values:

Ex: (Single Dimensional Arrays)


Multi-Dimensional Arrays:
o/p
ARRAYS IN C#:
Initialization and filling elements in Jagged array
IS Operator:

Ex:

o/p:
False
False
True
True
True
AS Operator:

Ex:
o/p:

ALL Constructors in 1 Program Example:

----------------------------------END---------------------------------------------------

You might also like