Saturday, May 18, 2013

Using Partial Class in Asp.net | Partial class Example

Suppose 4 developers are told to write method for add edit delete update inside one class. This is practically impossible all four of them writing the method simultaneously inside one class.

Using partial we can overcome this above scenario. Each of them will create a class with same name like "myclass" and that class will be defined as partial as given below:

partial class myclass
{
//code goes here
}

Using the above scenario lets create partial class for writing method for add update delete and edit.

1. Create separate class for all add update delete and edit.



2. Create partial class called myclass in all the class files as shown in below image and implement the method for all i.e add, update, delete and edit





Follow the above for the remaining class.

3. Now in the main class just create a object of myclass and then using this object u can call all the methods defined inside class myclass.



4. During compile time all partial class becomes one class.


5. Run the Project to get the desired output.





No comments:

Post a Comment