---
title: "Inheritance in C Sharp"  
description: "Inheritance allows us to  reuseexisting code  which saves time. It is basic concept of Object Oriented Programming (OOPS).  Here, I am going to  demon"  
author: "Anonymous User"  
published: 2010-07-17  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/80/inheritance-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Inheritance in C Sharp

Inheritance allows us to reuse existing code which saves time. It is basic concept of

Object Oriented Programming (OOPS).\

Here, I am going to demonstrate the use of inheritance through an example.

##### Example

![Inheritance in C Sharp](https://www.mindstick.com/mindstickarticle/98d42f70-9ece-4a8a-aea5-91f0e31828c5/images/f21a099f-0634-477b-9425-dd4d1103244c.png)

```
//creating instance ofchild class designation de = new designation();        private void btnAdd_Click(object sender, EventArgs e)   {//calling assign() function of parent class through child class  de.assign(int.Parse(txtID.Text),txtName.Text.Trim(), txtAddress.Text.Trim(), txtDOB.Text.Trim()); //calling function of child class     de.assign(txtDesig.Text.Trim(),txtBranch.Text.Trim());    } private void btnParent_Click(object sender, EventArgs e)  {//calling parent class display() method through instance of child class by type casting child class to //parent class.    ((employee)de).display();  }
```

![Inheritance in C Sharp](https://www.mindstick.com/mindstickarticle/98d42f70-9ece-4a8a-aea5-91f0e31828c5/images/fde10ecc-cd0e-4942-bf19-06c1e383dd45.png)

```
 private void btnChild_Click(object sender, EventArgs e)   {         //calling display() method of child class       de.display();    }
```

![Inheritance in C Sharp](https://www.mindstick.com/mindstickarticle/98d42f70-9ece-4a8a-aea5-91f0e31828c5/images/51c50531-906e-4861-ae38-f40fda09d792.png)

```
//creating parent class ‘employee’    public class employee    {        int id;        string name;        string address;        string dob;//constructor to initialize variables        public employee()        {            id= 0;            name= null;            address= null;            dob= null;        }         public void assign(int i, string n, string add, string d)        {//assigning values to variables            id= i;            name= n;            address= add;            dob= d;        }         public void display()        {//displaying values            MessageBox.Show("ID: " +id.ToString() + "\nName: " + name + "\nAddress:" + address + "\nDateof Birth: " + dob,"Parent");        }    } //creating child class ‘designation’ which will inheret ‘employee’. To inheret parent class we use colon (:)    public class designation : employee    {        string desig;        string branch;         public designation()        {            desig= null;            branch= null;        }         public void assign(string d, string b)        {//assigning values to variables of child class            desig= d;            branch= b;        }         public new void display()        {//calling display() method of base class            base.display();           //displaying values of variables of child class            MessageBox.Show("Designation: " + desig + "\nBranch: " + branch,"Child");        }
```

---

Original Source: https://www.mindstick.com/articles/80/inheritance-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
