With the complexity of today's applications, developers often deal with classes that are very long. One way to make the classes more manageable is to split them across multiple files. Partial is a new keyword in VB.NET that allows you to split the classes to multiple physical source files. You can also use Partial to allow using multiple files for a full class definition.
An ability to split a class definition over a number of source files is generally convenient for larger projects where a number of developers may need to work on a class at the same time, or when the class definition is too long and splitting it up would make it easier to handle.
You're required to use the Partial keyword in order to tell the VB complier to collect all pieces of the class before building it. If you use multiple files, you don't have to use this keyword in every part of the class -- just in one part. However, all pieces of the same class have to be defined within the same namespace.
The compiler treats the class as a union of all its partial declarations. Every modifier from every partial definition applies to the complete class.
Note: If you use a class that inherits from another class or implements an interface, it's enough to use the Inherits or Implements keyword in just one portion of the class.
An example of Partial
'class members defined here
Partial Class LongClass1
'additional class members defined here
Miss a tip?
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!