0% found this document useful (0 votes)
44 views9 pages

Datatype: Encapsulation: It Is The Programming Mechanism That Binds Together Code and The Data It

Encapsulation, polymorphism, and abstraction are key object-oriented programming concepts. Encapsulation binds code and data together into objects and protects them from misuse. Polymorphism allows one interface to access a general class of actions through different object forms. Abstraction refers to representing essential features without including details. C# supports value types that contain values directly and reference types that contain references to values stored elsewhere in memory. Object-oriented programming organizes programs around data by giving data control over code access through methods. Classes define types of objects, and objects are instances of classes that take up memory and have identities. Inheritance and method overriding allow derived classes to extend and modify base class behavior.

Uploaded by

Pankaj Anjikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views9 pages

Datatype: Encapsulation: It Is The Programming Mechanism That Binds Together Code and The Data It

Encapsulation, polymorphism, and abstraction are key object-oriented programming concepts. Encapsulation binds code and data together into objects and protects them from misuse. Polymorphism allows one interface to access a general class of actions through different object forms. Abstraction refers to representing essential features without including details. C# supports value types that contain values directly and reference types that contain references to values stored elsewhere in memory. Object-oriented programming organizes programs around data by giving data control over code access through methods. Classes define types of objects, and objects are instances of classes that take up memory and have identities. Inheritance and method overriding allow derived classes to extend and modify base class behavior.

Uploaded by

Pankaj Anjikar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Encapsulation: It is the programming mechanism that binds together code and the data it

manipulates and that keeps both safe from outside interface and misuse.
When code and data are link together object are created.

Polymorphism: it is a quality that allow one interface to access a general class of action
It represents ability of object to take more than one form
In simple term polymorphism is a attribute that allow one interface to control the access to
general class of action

Abstraction: it refer act of representing essential feature without including g big


detail

EarlyBinding/Comple time Polymorphism-> function overloading


Late binding/Runtime Polymorphism-> virtual

In most general program can organize in two type


1. Around its code 2. Around its data
In Structural programming is typically organized around it s code, its approach is
code around data

In Oops they are typically organized around data, its approach like data control
access to code
U defined data & give permission to function to act on it.

OOPs: it is problem solving technique to develop software system. it is a tech to


think real word in term of object, this object have responsibility and provide services
to application or other object.

Class: class is a blue print for a object, for one class several object can created class
describe all attribute of object as well as method that implement the behavior of
member object.

Object: object is nothing but a variable of class, object is a basic entity that has
attribute behavior & identity.
Programming problem can analyze in term of object & nature of communication
between them
It take a space in memory & has associate address

DataType
C# contains two general categories of build in data type.
1. Value type 2.Refrance type.

Value Type: variable of this type contain there value directly, it saves on stack.
Reference Type: variable of this type contain the reference of actual value, it saves
on manage heap.
C# provide 2 type of predefined reference type

Object: it the root type from which all other type r derived (check it), object type is
ultimate parent type from which all other intrinsic & user defined type are derived.
String: Unicode character string.
Type Conversion & Casting

Two type of conversion automatically and explicitly

Automatic (implicit) Conversion:

When one type of data is assigned to another type of variable and automatic type
conversion will take place if
1. Two type are compatible
2. Destination type has range greater than source type
When this two condition met widening conversion take place i.e. int type always
large enough to hold all valid byte value and both int & byte are integer type so
automatic(implicit) can applied

Explicit Conversion:

There are many conversion that can not be implicitly made between type and
compiler will give an error .these are some conversion that can not be made
implicitly
1.int to short—may loose data
2.int to uint
3 float to int will lose everything after decimal point
When cast involved a narrowing conversion happened and information might be loss.
Long val=3000;
Int i=(int) val --------valid cast

Programming control statement

While:

while (myInt < 10)


        {
            Console.Write("{0} ", myInt);
            myInt++;
        }

Do While:

do
       {
            // Print A Menu
            Console.WriteLine("My Address Book\n");   
   } while (myChoice != "Q" && myChoice != "q"); // Keep going until the user
wants to quit

Switch:
Switch provides multiway brance.
Switch expression must be integer or character. but floating point expression are not
allowed.
switch(myChoice)
            {
                case "a":
                    Console.WriteLine("You wish to add an address.");
                    break;
                case "q":
                    Console.WriteLine("Bye.");
                    break;
                default:
                    Console.WriteLine("{0} is not a valid choice", myChoice);
                    break;
            }

For Loop

  for (int i=0; i < 20; i++)


        {

            Console. Write ("{0} ", i);


        }

FOR Each

for each (string person in names)


        {
            Console.WriteLine("{0} ", person);
        }

Infinite loop

For (; ;)
{
}

Continue:
Continue statement forces the next iteration of the loop to take place, skipping any
code in-between. This continue is complement of break
For (int i=0;i<=100;i++)
{
If(i>5) continue;
Console.writeline(“hi”);
}

Method
Method are subroutine that manipulate the data defined by class and in many cases
provide access to the data typically other part of your program will interact through
the method. Methods are public or private if method is private then it is available to
the code with in the class itself.

Constructor

Constructor initialize the object when it is created, it has same name as its class and
is syntactically similar to the method however the constructor have no explicit the
return type.

Public building()
{
}

Typically it used to give initial value to the instance variable defined by the class or
to perform any other start up procedure
require to create fully formed object. Usually object are public because constructor
are normally called from outside their class
If you are not define your won constructor C# automatically provide a default
constructor that initialize all member variable to zero(for value type) or Null(for
reference type)
However once u define your own constructor default is not longer used.
(thats why we make string=“ ”; since first time constructor make it null)

Garbage Collector
Garbage collector work for recovery of free memory from unused object, making that
memory available for subsequent reallocation.
It works like this “ when no reference to the object exists that object is
assumed to be no longer needed& the memory occupied by that object is
released by CLR” , this recycle of memory can then used for subsequent allocation

Garbage collector work for manage object if your object using any unmanaged
resource then u need to take care about releasing the resource beforeObject release.
This can do using finalizer /Dispose method.

Destructor
It is possible to define the method that will be called prior to an object final
destructor by the garbage collector.
This method is called desctrutor and it can be used to ensure that an object
terminate clearly.
U might use destrctur to make sure that an open file owned by that object is closed

~classname()
{
GC.Suppressfinalize()
}
This Keyword
When method is called ,it is automatically passed on implecite argument that is a
refrance to the invoking object(that is the object on which the method is called) this
reference is called THIS (to know which object call it).

Pass by value Pass by Reference

Calling BASE class constructor


Derived class can call base class constructor by using expanded form of derived class
constructor declaration and the “BASE” keyword.

Class b1
{
Int a,b
Public b1(int c ,int d)
{
a=c;
b=d;
}

Class b2:b1
{
Int m,n,o;

Public b2(int x, int y, int z):Base( int x, int y)


{

Method Overloading
In C# two or more method within the same class can share the same name as long
as their parameter declaration are different this method called overloaded method.

Inheritance & Name Hiding

It is possible for and derived class to define a member that has the same name as a
member it its base class.
If same member is defined in derived class the it is defined with new keyword
(Class member must be preceded by “NEW” keyword)
Derived class member hide the base class member & if we want to access the base
class member then access it by using Base. Classmember()

Using system;

Class A
{

Public int i=0;


}

//derived class

Class B:A
{
New int I; // this I hide the I in class A

public B(intb)
{
I=b;
}

Public void show()


{

c.w.(“inderived class”+i);
c.w(“in base(A) class”+base.i);
}

Hiding Method

If the method with same signature is declare in both base and derived class but the
method are not declared as virtual
Override respectively then the derived class version is said to hide the base class
version.

Class A
{

Public int i=0;

Public void show()


{
c.w(“in base”);
}
}
//derived class

Class B:A
{
New int I; // this I hide the I in class A

public B(intb)
{
I=b;
}

NEW Public void show()


{
c.w(“in base”);
}
}
Virtual Method
Virtual method is a method that is declared as a virtual in a base class and redefined
in one or more derived class thus each derived class can have its won version of
virtual method.
C# determine which version of method to call base on the type of object reference
by base class reference and this determination is made @ runtime, Thus when a
different type of object r referred to different version of virtual method are executed.
Method overriding forms the basis for one of the C# most powerful concept
“Dynamic Polymorphism”.
Dynamic method dispatch is the mechanism by which a call to overridden method is
resolved at runtime rather than compile time.

What is Method Overriding How to override a function in C#?

An override method provides a new implementation of a member inherited from a


base class. The method overridden by an override declaration is known as the
overridden base method. The overridden base method must have the same signature
as the override method.
You cannot override a non-virtual or static method. The overridden base method
must be virtual, abstract, or override.

Class Base
{
Public virtual void who ()
{
c.w (“who is in Base”);

Class Derived1: Base


{
Public override void who()
{
c.w (“who is in derived1”);

Class Derived2: Base


{

Public override void who()


{
c.w (“who is in derived2”);

Class demo
{

Public static void main()


{
Base B1 = new Base();
Derived1 d1 = new Derived1();
Derived2 d2 = new Derived2();

Base b;

B=B1;

b.who();

B= d1;

b.who();

B= d2;

b.who();

Output
who is in Base
who is in derived1
who is in derived2
Why Overridden Method:

Overridden Method allow C# support runtime polymorphism


Polymorphism essential to oops for one reason, it allow a general class to specify
method that will be common to all of its derivatives, while allowing derived class to
define the specific implementation of some or all of those method. override method
are another wany that C# implement the one interface multiple method aspects of
polymorphism.

ABSTRACT Method:
Some time you will want to create a base class that define only generalize form that
will be share by all of its derived classes leaving it to each derived class to fill in the
detail such a class determines the nature of the method that deri9ve class must
implemented.

C# allows both class and function to be declared as abstract .an abstract class can
not be instantiated while an abstract function does not have an implementation &
must be overridden in any non abstract derive class. obviously an abstract function
is automatically virtual(don’t need to mention virtual)
If any call contain any abstract function then that class is also abstract.
Abstract class twoshape
{
Public abstract double area()
}
Class reatangle :twoshpae
{
Public overridden double area()
{
}
}

You might also like