Posts

Showing posts from August, 2018

What is Inheritance in C# .Net ?

Inheritance: Inheritance is the strong concept of the world of object-oriented programing. In a Simple word, The mechanism of accessing or extending the behavior or properties of an existing class is known as Inheritance. For an example, If a class has methods let say Add(int s, int n) and its added two given values. So if we are going to create any class and we want to create an Add function of two variable then why we create it from scratch if this is available in an existing class. Yes, We can use the Add function of existing class in a new class as below: public class ExistingClass {    public int Add(int s, int n)    {       return s+n;    } } and the new class is: public class NewClass : ExistingClass {    base.Add(110,210); // this will call the existing methods }

What is Object in C# ?

An object is a real-time entity by which a class comes into existence. Without creating the object we can not use the class. For Example: public class MyClass {    int x=10;   public void MyFunction()   {      Console.WriteLine(x.ToString());    } } If we want to use the MyClass's MyFunction in another class then we have to create an object of MyClass in another class like below: public class MyOtherClass { //  Here we want to use the MyFunction of MyClass the create an object of this.     MyClass obj=new MyClass(); // By this line of code object will be created and stored as "obj".    //Now by the help of this "obj" we can call the MyFunction(); as below.    obj.MyFucntion(); } Output: 10. What is Inheritance in C# .Net ?

What is Class in C# ?

In Opps/C# everything written in a class, unlike procedural language C. So a class is a template, block, unit or blueprint that contains the data member (variable/properties) and its member functions.  A class must be defined by a keyword "class". public class MyClass {     int x=10;  // Data member;       public void MyFunction(); // Member Function;   } What is Object in C# ?