Imports statments

M

Mike W

I have a class that requires the Imports System.IO statement to function
properly. I intend on reusing this code in the future.
I have another class in the project also need the system.io statement.
Is it a bad practice to insert the import statement in both classes?
Can I place the imports statement somewhere that both classes can share or
does it need to be in both classes?

Since I plan on reusing the first class, it seems convenient to have the
imports statement in that class but it would be nice if there was a place to
globally import a namespace.

Thanks,
m
 
G

Guest

Mike said:
I have a class that requires the Imports System.IO statement to function
properly. I intend on reusing this code in the future.
I have another class in the project also need the system.io statement.
Is it a bad practice to insert the import statement in both classes?
Can I place the imports statement somewhere that both classes can share or
does it need to be in both classes?

Since I plan on reusing the first class, it seems convenient to have the
imports statement in that class but it would be nice if there was a place to
globally import a namespace.

Thanks,
m

It is by design that you can use the import in multiple class files.
There is no downside to doing it. You don't even have to put the import
statement at the top of the file, it just saves typing in the class.
You could change your code to put "system.io" in front of ever object
that uses that namespace and forget about putting the import statement
at top. The import statement end the end is just a shortcut.

Chris
 
M

Mike W

Thanks. That makes sense. Adding the system.io to the couple of instances
that need it is so obvious I'm embarrassed I didn't think of it.
This is why the community is so great, IMO.
Thanks again.

-m
 
O

Oenone

Mike said:
Since I plan on reusing the first class, it seems convenient to have
the imports statement in that class but it would be nice if there was
a place to globally import a namespace.

You can globally (for the whole of your project) import a namespace from
within your project's properties window.

In VS2003, open the Project Properties window and select the Common
Properties/Imports section in the left panel. Namespace can then be
specified to be globally imported.

In VS2005, open the My Project window and click on the References tab. The
namespaces are specified at the bottom of the window.

HTH,
 
H

Herfried K. Wagner [MVP]

Mike W said:
I have a class that requires the Imports System.IO statement to function
properly. I intend on reusing this code in the future.
I have another class in the project also need the system.io statement.
Is it a bad practice to insert the import statement in both classes?

No, it isn't. It's IMO good practice.
Can I place the imports statement somewhere that both classes can share or
does it need to be in both classes?

You could add a project-wide import in the project properties. Note that
this will import the namespace in all source files of your project
automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top