Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

OOP'S Concept in C#:-


OOP'S means Object Oriented Programming Structure, It is used to create a real-world based application which provide dynamic memory allocation, security, reusability, extendibility features in an application.

C# Programming language follows 80 to 90% features of oop's but it is not 100% Object-oriented because it supports primitive datatype which has been created in c and CPP languages.


Features of OOP'S:-


1)  Security ----->   Data abstraction and Data Encapsulation

2)  Extendibility:-     Polymorphism

3)  Reusability:-       Inheritance

4) Accessibility:-       Access Specifier

5) Usability:-     Static Polymorphism

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Class and Object:-

Class:-   It is a user-defined datatype which will work as a blueprint of an object , Object definition will be contained underclass.

We can define data members, member function, constructor, properties underclass.


Object:-   It is a real-world entity which has an identity, state, and behavior, Object address will work as an identity, Memory allocation will work as a state and we can store and call data member and member function under Object is called behavior.


Syntax of class:-

class Classname
{
        Data member ;  //variable
        Member Function ;
        Main Function ();

}

Syntax of Object:-

Classname obj = new Classname();
obj.FunctionName();



class Student
    {
        int rno;
        String sname;
        void Accept()
        {
            Console.WriteLine("Enter rno");
            rno = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter name");
            sname = Console.ReadLine();

        }
        void Display()
        {
            Console.WriteLine("Rno is " + rno + " Sname is " + sname);
        }
        static void Main()
        {
            Student obj = new Student();
            obj.Accept();
            obj.Display();
            Student obj1 = new Student();
            obj1.Accept();
            obj1.Display();
            Console.ReadKey();
        }
    }



Component of class:-

1) Data Member:-   It is also called variable, it is used to define the attribute of Object, Data member will be defined using two different ways

1)  Static Data Member:-  IT is also called class type data member,it will allocate memory when we compile the program.  It has constant memory means we can not re-create memory for static data members.

static datatype identifier=value.

static int x;

2) An instance or Dynamic Data Member:-  This type of data member will be called by Object at run time,

datatype identifier=value;

int x;

 class StaticDynamic
    {
        static int x = 100;  //static variable
        int y = 200;  //dynamic variable
        static void Main()
        {
            Console.WriteLine(StaticDynamic.x);
            StaticDynamic obj = new StaticDynamic();
            Console.WriteLine(obj.y);
            Console.ReadKey();
        }
    }


Member Function:-  It is used to define static data members and dynamic data members.  static member function will be defined under static data members. dynamic member function will be used to define dynamic data members.

Type of Member Function:-

1)  Static Member Function:-

It will be called by Class name

static  ReturnType  FunctionName()
{

}
class StaticMemberFunction
    {
        static int a,b,c;
        static void Addition()
        {
            a = 100;
            b = 200;
            c = a + b;
            Console.WriteLine(c);
        }
        static void Main()
        {
            StaticMemberFunction.Addition();
            Console.ReadKey();
        }
    }

1)  Dynamic Member Function:-   It will be called by Object


  ReturnType  FunctionName()
{

}


 class DynamicMemberFunction
    {
        int a,b,c;
        void Addition()
        {
            a = 100;
            b = 200;
            c = a + b;
            Console.WriteLine(c);
        }
        static void Main()
        {
           DynamicMemberFunction obj = new DynamicMemberFunction();
           obj.Addition();
           Console.ReadKey();
        }
    }


Type of Member Function According to Parameters:
1)  Default:-  We can not pass any value from parameters all value will be declared under method block.
1.1 Without Return type:-
void Method1()
{

 
}
1.2 With Return Type

int Method1()
{

 
}

 class DynamicMemberFunction
    {
        int a,b,c;
        void Addition()
        {
            a = 100;
            b = 200;
            c = a + b;
            Console.WriteLine(c);
        }
        int AdditionProgram()
        {
            a = 100;
            b = 200;
            c = a + b;
            return c;
        }
        static void Main()
        {
           DynamicMemberFunction obj = new DynamicMemberFunction();
           int c= obj.AdditionProgram();
           Console.WriteLine(c);
           Console.ReadKey();
        }
    }


Parametrized:-  We can pass parameters to calling function to called function, which means input will be decided at run time.

 class ParametrisedFunctionExample
    {
        void Addition(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        int Subtraction(int x, int y)
        {
            return x - y;
        }
        static void Main()
        {
            ParametrisedFunctionExample obj = new ParametrisedFunctionExample();
            obj.Addition(1000, 200);
            int res = obj.Substraction(100,20);
            Console.WriteLine(res);
            Console.ReadKey();
        }
    }


               

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post