Partial class is a new functionality that is included in Visual Studio .Net 2005 and is supported in ASP.Net 2.0. This new functionality helps you to split a single class into multiple partial classes. These partial classes can be in different individual files.
In the previous versions of the Visual Studio .Net IDE, when you create a new ASP.Net webform, the name of the web form is used as a class in the code-behind file. Apart from that, you would have seen lots of code generated by Visual Studio .Net itself. In the latest version of the Visual Studio .Net IDE, the codes that are generated by Visual Studio .Net are in a separate file as a partial class. Hence a user who creates a new webform would see a partial class for that page, when the user uses the code-behind file. This way the code that is seen in the code-behind file is minimal for a particular webform.
The code given below gives the implementation of the partial classes.
'-----File_1.vb
Imports System
Interface IPartialClass
Sub PrintEmployeeName(ByVal sName As String)
Sub PrintEmployeeName()
End Interface
Partial Class MyPartialClass
Private sName As String = "sName Variable - John Peter - From Partial Class."
End Class
'-----File_2.vb
Imports System
Partial Public Class MyPartialClass
Implements IPartialClass
Public Sub PrintEmployeeName(string str)
Response.Write(str)
End Sub
End Class
'-----File_3.vb
Imports System
Partial Public Class MyPartialClass
Public Sub PrintEmployeeName()
Response.Write(sName)
End Sub
End Class
if you are writing your code for partial classes in C#, it is necessary for all the classes to have the ‘partial’ keyword. This is a significant difference between VB.Net and C# in using partial classes
Since we are dealing with different files for a single class, even if you missed out implementing one method of an interface, the intellisense of Visual Studio .Net 2005 will point it out to you, thus enabling you to implement the missed out method of the interface. This is one among the advantage of using a Visual Studio .Net 2005 IDE for ASP.Net 2.0 applications.
This type of splitting the class file is particularly useful if a single class runs to thousands of lines of code with different functionalities across different methods. Productivity of the project team is increased since a single class file is split across the team members and implemented as partial classes.