How to generate partial class in c#?
In this article I am going to discuss about partial classes in c#. Partial class provides a facility to create single class file code to multiple class files. "Partial" keyword is used to implement the partial class.
2- ExamplePartialClass2.cs
On run time compiler will combine both the classes and make as one class.
Prerequisite for Partial class
1- ExamplePartialClass1.cs
public partial class ExamplePartialClass { public ExamplePartialClass() { } public void Method1(int arg) { Console.WriteLine(arg); } }
2- ExamplePartialClass2.cs
public partial class ExamplePartialClass { public void Method2(int arg) { Console.WriteLine(arg); } }
On run time compiler will combine both the classes and make as one class.
public class ExamplePartialClass { public ExamplePartialClass() { } public void Method1(int arg) { Console.WriteLine(arg); } public void Method2(int arg) { Console.WriteLine(arg); } }
Prerequisite for Partial class
- All the members of class must have the same access specifiers like public or private, etc
- If any member of class is declared abstract, sealed or base type then the whole class is declared of the same type.
- Each and every partial class must be defined in the same assembly and namespace.
0 comments :
Post a Comment