Wednesday , October 17 2018
Home / Dot Net / C# / Partial Class in C#

Partial Class in C#

1.Partial Class:

Partial Class is a special type of class and it is introduced with .Net Framework 2.0. Partial Class allows its members – method, properties, and events – to be divided into multiple source files (.cs). At compile time these files get combined into a single class.

A Partial class splits the definition of a class over two or more source files. You can create a class definition in multiple files but it will be compiled as one class.

There are several situations when splitting a class definition is desirable:

  • When working on large projects, spreading a class over separate files enables multiple 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 uses this approach when it creates Windows Forms, Web service wrapper code, and so on. You can create code that uses these classes without having to modify the file created by Visual Studio.

Example:

Here we have created student class in two times if you removed Partial Keyword then immediately  compiler will returns Error but this time it wont return any error and we can access members and methods of student class by using single object.

BackTo Classes

Print Friendly, PDF & Email

Give us your valuable feedback

comments

About Murali

Hello everyone I am Software Developer having 3+ years of Experience in Microsoft Technologies and Others. My skills :- Asp.net, C#,Ado.net, SQL SERVER, web services, windows Service,Windows applications,HTML,CSS, JavaScript,JQuery,AnjularJs

Check Also

Studyclues_C#_Date Format

Date Formatting in C#

Date Formats in C#: Date Formatting in C# is a date and time format string …