Each class in C# resides in a separate physical file with a .cs extension. C# provides the ability to have a single class implementation in multiple .cs files using the partial modifier keyword. Thepartial modifier can be applied to a class, method, interface or structure.
Why to use Partail Class: 1.When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.
2.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. 3.To split a class definition, use the partial keyword modifier, Please see the example given bellow.
Example: public partial class Employee { public void DoWork() { //Some Code } } public partial class Employee { public void GoToLunch() { //Some Code } }
after this we can create the object of class. and call the methods. Employee e=new Employee (); e.DoWork(); e.GoToLunch(); It should helpfull for your question.
Breaking a single class into multiple parts is called as a partial class. This can be done in case of a struct or an interface and a method too.
The adventages of using partial classes comes to use when programmers are working on large sized projects. This will help them to work all on the same at the same time.
To split a class use the keyword modifier partial.
A partial class is simply a class that's contained in more than one file. Sometimes it's so that one part can be machine-generated, and another part user-defined