locked
Help on Imports in VB, please. RRS feed

  • Question

  • User2019633211 posted

    Hello!-

    As a new developer, I don't understand when and what Imports to use at the top of the code behind file.  I understand they allow acces to different namespaces and classes which allows different functionality (I believe), but how do I know when I should be adding them?

    Would it be good practice to just add them on every page (or in the code behind of master page), something like this:

    Imports System.Web.UI.WebControls
    Imports System.Net.Mail
    Imports System.IO
    Imports System.Linq
    Imports System.Web.UI
    Imports System.Web.Security
    Imports System.Collections.Generic
    Imports System
    Imports System.Web

    and then I would always have it covered, or does that slow the system down?

     

     

     

     

    Monday, August 9, 2010 1:58 PM

Answers

  • User-1825045995 posted

    the compiler will ignore namespaces not used. If you add a class and it's not in one of the listed namespaces at the top of your code file(Imports) then you must add it.

     

    this add in works wonders for cleaning your code up and adding references when needed. tons more

     

    http://www.jetbrains.com/resharper/ incredible tool.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 9, 2010 2:20 PM

All replies

  • User-1825045995 posted

    the compiler will ignore namespaces not used. If you add a class and it's not in one of the listed namespaces at the top of your code file(Imports) then you must add it.

     

    this add in works wonders for cleaning your code up and adding references when needed. tons more

     

    http://www.jetbrains.com/resharper/ incredible tool.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 9, 2010 2:20 PM
  • User2019633211 posted

    Thank you! 

    Tuesday, August 10, 2010 12:27 PM