---
title: "C# Partial Class"  
description: "There are several situations when splitting a class definition is desirable:When working on large projects, spreading a class over separate files enab"  
author: "Uttam Misra"  
published: 2012-05-19  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/309/c-sharp-partial-class  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# C# Partial Class

##### There are several situations when splitting a class definition is desirable:

- When working on [large projects](https://www.mindstick.com/forum/159481/how-does-c-plus-plus-handle-namespaces-and-what-is-their-significance-in-large-projects), spreading a class over separate files enables [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) programmers to work on it at the same time.
- When working with automatically generated source, code can be added to the class without having to recreate the source file. [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) uses this approach when it creates Windows Forms, [Web service](https://www.mindstick.com/articles/895/web-service-introduction) wrapper code, and so on. You can create code that uses these classes without having to modify the file created by Visual Studio.

To split a class [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat), use the partial keyword modifier, as shown here:

##### C#

\

```
public partial class Calculation{    public void Sum()    {    }}public partial class Calculation{    public void Multiplication()    {    }}
```

The partial keyword indicates that other parts of the class, struct, or [interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces) can be defined in the namespace. All the parts must use the partial keyword. All the parts must be available at compile time to form the final type. All the parts must have the same [accessibility](https://www.mindstick.com/blog/304975/why-image-alt-text-matters-for-seo-and-accessibility), such as public, private, and so on.

If any part is declared abstract, then the whole type is considered abstract. If any part is declared sealed, then the whole type is considered sealed. If any part declares a base type, then the whole type inherits that class.

All the parts that specify a [base class](https://www.mindstick.com/blog/116/base-class-initilization) must agree, but parts that omit a base class still inherit the base type. Parts can specify different base [interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example), and the final type implements all the interfaces listed by all the partial declarations. Any class, struct, or interface members declared in a partial definition are available to all the other parts. The final type is the combination of all the parts at compile time.

---

Original Source: https://www.mindstick.com/blog/309/c-sharp-partial-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
