473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Imports statments

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
Dec 1 '05 #1
4 991
Mike W wrote:
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
Dec 1 '05 #2
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

"I Don't Like Spam" <no@spam.com> wrote in message
news:ej**************@tk2msftngp13.phx.gbl...
Mike W wrote:
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

Dec 1 '05 #3
Mike W wrote:
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,

--

(O)enone
Dec 1 '05 #4
"Mike W" <th********@yahoo.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Angelina | last post by:
Hi, I need some help in writing a 'if-then-else' statement. I currently have wrote one that looks something like this.. If Combobox1 = xxx and textbox1 <> "" then 'run stored procedure 1 to...
4
by: Jesper | last post by:
Hi, I would like to issue three statements to the database (mysql v4.1) each time the server starts up. Is there any built in way to do this? Like a init file to put them in? At the moment I...
3
by: Vinny Vinn | last post by:
I have used simple batch statments with C#.for example: string select = "select model from cars where id = ?;select * from trucks where model = ?"; where ? is a parameter whose value i have...
5
by: orencs | last post by:
Hello, I am using Microsoft.Practices.EnterpriseLibrary.Data. I am running the following sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT var3 FROM table2 WHERE var2 IN...
1
by: Syl | last post by:
Hello! Can someone verify this for me please. Should these 2 statments return the same result ? The 2nd one is the original, the first one is my re-write. Thanks : SELECT orders_status,...
2
by: lee | last post by:
Newbie question: I'm looking for the easiest way to run SQL statments in Access. I'm getting confused by th GUIs - I'm just looking forhow to run SQL on a table- thanks
5
by: kimiraikkonen | last post by:
Hello, I want to ask about "imports" statement. Some projects must be inserted with "imports xxxx" statements before beginning coding. But how do i know when to use or do i have to use "imports"...
2
by: ramdil | last post by:
Hi All Please help me .Hope i have described my problem clearly below. I have a condition where i need to update some data in table from the value taken from another table.So basically i need to...
3
by: Mohamed Yousef | last post by:
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.