---
title: "Partial Class in C#"  
description: "In this blog, I’m trying to explain the concept of partial class in c# and how to implement it.  A Partial class is one that can be split among multip"  
author: "Sumit Kesarwani"  
published: 2013-05-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/494/partial-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Partial Class in C#

In this blog, I’m trying to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of [partial class](https://www.mindstick.com/forum/155717/define-partial-class-in-mvc) in c# and how to implement it.\

A Partial class is one that can be split among multiple physical files. This feature was introduced with the release of C# version 2.0. With C#, we can split the [source code](https://www.mindstick.com/forum/33476/pls-send-me-source-code-for-changing-passward-in-asp-dot-net-i-tried-so-much-from-google-but-its-not-workining) for a class into separate files so that we can organize the [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) of a large class into smaller, easier to manage pieces. When we split a class across [multiple files](https://www.mindstick.com/forum/33990/attach-multiple-files-gridview-row-in-knockout-js), we define the parts of the class by using the partial keyword in each file. Each file contains a section of the class definition, and all parts are combined when the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) is compiled.

##### Example

\

```
using System; namespace PartialClassConsoleApplication{    public partial class Add    {        int x, y;        public void getvalue(int x, int y)        {            this.x= x;            this.y= y;        }    }    public partial class Add    {        public void add()        {            Console.WriteLine("Addition of "+ x + " & "+ y + " = "+ (x + y));        }    }    class Program    {        static void Main(string[] args)        {            Add aobj = new Add();            aobj.getvalue(4, 6);            aobj.add();        }    }}
```

##### Output:-

Addition of 4 & 6 = 10

In this example, I’ve created a class named Add and split it into two parts with partial keyword. In one part , declared [two variables](https://www.mindstick.com/forum/236/how-can-i-swap-two-variables-without-using-a-third-variable) x, y and assign value to them through [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) getvalue() and in other part created a function named add() who add the values of x and y and print the values.

---

Original Source: https://www.mindstick.com/blog/494/partial-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
