.NET Tips and Tricks

Blog archive

Eliminate Import Statements from Your Code in Visual Basic

A surprising number of Visual Basic programmers (i.e., more than one) aren't aware of a feature unique to their language: Project-level Imports. Namespaces added to the list of project-level Imports are, effectively, automatically added to the code files that make up your application --there's no need to add Import statements to the top of the code file for those namespaces.

You can add or remove project-level Imports by opening your Project's properties (right-click on the project in Solution Explorer and select Properties) and selecting the References tab. The list of project-level Imports appears at the bottom of the resulting form. Adding a namespace there means that you don't have to include it in your code file.

There is a wrinkle with using project-level Imports, however: If you remove the libraries whose namespaces are referenced in the Imports, your application will stop compiling. You'll need to track those Imports down and delete them. The good news here is that, instead of those Imports being scattered through your code files, they're all in one place -- though, perhaps, not an obvious place.

Posted by Peter Vogel on 01/23/2014


comments powered by Disqus

Featured

Subscribe on YouTube