Difference between Procedural and Object Oriented Programming

Procedural Oriented ProgrammingObject Oriented Programming
In procedural programming, program is divided into small parts called functions.
Example code :
#include <stdio.h>
/*this function computes the absolute value of a whole number.*/
int abs(int x)
{
if (x>=0) return x;
else return -x;
}
/*this program calls the abs() function defined above twice.*/
int main()
{
int x,
printf(” x=”);
scanf(“%d”, &x);
printf(“Absolute Value of x is %d. \n”, abs(x));
return 0;
}
In object oriented programming, program is divided into small parts called objects.
Example code :

class Parrot:
# class attribute
species = "bird"
# instance attribute
def __init__(self, name, age):
self.name = name
self.age = age
instantiate the Parrot class
blu = Parrot(“Blu”, 10)
woo = Parrot(“Woo”, 15)
access the class attributes
print(“Blu is a {}”.format(blu.class.species))
print(“Woo is also a {}”.format(woo.class.species))
access the instance attributes
print(“{} is {} years old”.format( blu.name, blu.age))
print(“{} is {} years old”.format( woo.name, woo.age))
Procedural programming follows top down approach.
Note: A top-down approach is essentially the breaking down of a program to gain insight into its compositional small program (or module) in a reverse engineering fashion.
Object oriented programming follows bottom up approach.
Note : A bottom-up approach is the piecing together of module (or small program) to give rise to more complex program, thus making the original modules of the emergent program.
There is no access specifier in procedural programming.Object oriented programming have access specifiers like private, public, protected etc.
Adding new data and function is not easy.Adding new data and function is easy.
Procedural programming does not have any proper way for hiding data so it is less secure.Object oriented programming provides data hiding so it is more secure.
In procedural programming, overloading is not possible.Overloading is possible in object oriented programming.
Overloading methods lets you define the same method multiple times so that you can call them with different argument lists (a method’s argument list is called its signature)
In procedural programming, function is more important than data.In object oriented programming, data is more important than function.
Procedural programming is based on unreal world.Object oriented programming is based on real world.
Data can move freely from procedure to procedure in the systemObjects can move and communicate with each other through member functions
Examples: C, FORTRAN, Pascal, Basic etc.Examples: C++, Java, Python, C# etc.
Difference between Procedural and Object Oriented Programming

How to call Constructor from another Constructor with same class in C# ?

Calling Constructor from another Constructor with same class

There are two ways to do the above :
1. Use this keyword to acheive this . Example below :
 public class Employee
{
    public Employee(): this(10)
    {
        // This is the no parameter constructor method.
        // First Constructor
    }
    public Employee(int Age)
    {
        // This is the constructor with one parameter.
        // Second Constructor
    }
}
So first constructor will can second constructior using this keyword
2.
public class Employee
{
    public Employee()
    {
        Employee(10)
        // This is the no parameter constructor method.
        // First Constructor
    }
    public Employee(int Age)
    {
        // This is the constructor with one parameter.
        // Second Constructor
    }
}

What is Construction Overloading in C#

Constructor Overloading
Constructor oveloading enables to have constructors with different sets of parameters.

Example below:

public class Employee
{
    public Employee()
    {
        // This is the no parameter constructor method.
        // First Constructor
    }
    public Employee(int Age)
    {
        // This is the constructor with one parameter i.e. Age.
        // Second Constructor
    }
    public Employee(int Age, string Name)
    {
        // This is the constructor with two parameters i.e. Age and Name.
        // Third Constructor
    }
   
}
Call to the constructor now depends on the way you instantiate the object.

For example:

Employee objEmp = new Employee()
// At this time the code of no parameter 
// constructor (First Constructor)will be executed
Employee objEmp = new Employee(12)
// At this time the code of one parameter 
// constructor(Second Constructor)will be
// executed.