On The Insider: Paris Says Palin Has a Hot Bod

Splitting a class across files in VB.NET

Tags: Microsoft development tools, Programming languages, Irina Medvinskaya, Microsoft Visual Basic.Net, compiler, Visual Basic Tips Newsletter

  • Save
  • Print
  • 1

Takeaway: VB.NET's Partial keyword allows you to split very long classes to multiple physical source files. Learn more about using the Partial keyword, and see a code example.

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 LongClass1
      'class members defined here
End Class

Partial Class LongClass1
      'additional class members defined here
End Class

Miss a tip?

Check out the Visual Basic archive, and catch up on the most recent editions of Irina Medvinskaya's column.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

  • Save
  • Print
  • 1

Print/View all Posts Comments on this article

This is new to 2005?mattohare@...  | 05/05/07
RE: This is new to 2005?winthepro@...  | 05/06/07

What do you think?

SponsoredWhite Papers, Webcasts, and Downloads

Article Categories

Security
Security Solutions, IT Locksmith
Networking and Communications
E-mail Administration NetNote, Cisco Routers and Switches
CIO and IT Management
Project Management, CIO Issues, Strategies that Scale
Desktops, Laptops & OS
Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
Data Management
Oracle, SQL Server
Servers
Windows NT, Linux NetNote, Windows Server 2003
Career Development
Geek Trivia
Software/Web Development
Web Development Zone, Visual Basic, .NET
advertisement
Click Here