473,394 Members | 1,663 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,394 software developers and data experts.

VB.NET classes, imports, and namespaces



Is the whole System namespace automatically imported?

Oct 11 '06 #1
6 2449
Assuming VS.NET check the project properties. You'll find a list of
automatically imported namespaces...

--
Patrice

<do************@earthlink.neta écrit dans le message de news:
11*********************@m7g2000cwm.googlegroups.co m...
>

Is the whole System namespace automatically imported?

Oct 11 '06 #2
do************@earthlink.net wrote:
Is the whole System namespace automatically imported?
Using Visual Basic, you do get an automatic Import for System.

But that /only/ includes the stuff in System itself.
It /doesn't/ include all the "subsections" of System, like System.Data,
System.Xml, etc., etc.

HTH,
Phill W.
Oct 11 '06 #3
Yes and No,

If you create a notepad file code.vb with a main method you will find that
Console.WriteLine will cause a compiler error unless you add Imports
System.

Visual Studio automatically adds a few namespaces and references to common
assemblies depending on what project you create.

However, System.dll is always included when you compile so no need to add
a reference to it.

On Wed, 11 Oct 2006 04:36:05 +0200, <do************@earthlink.netwrote:
>

Is the whole System namespace automatically imported?


--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 11 '06 #4

Morten Wennevik wrote:
Yes and No,

If you create a notepad file code.vb with a main method you will find that
Console.WriteLine will cause a compiler error unless you add Imports
System.

Visual Studio automatically adds a few namespaces and references to common
assemblies depending on what project you create.

However, System.dll is always included when you compile so no need to add
a reference to it.

Fascinating.

I guess VB.NET tries to hide complexity from you. But, i am curous, at
what point do these namespaces get added? Does the simple fact that
the System.dll is included mean that the IDE automatically knows that a
String is a System.String? Or, is it through a command line option when
it compiles? Through some import code it automatically adds to the
code you write?

I know it works, but I'm just curious, for the VB.NET experts out
there, at what point does the magic happen?

--
http://www.douglassdavis.com

Oct 12 '06 #5
It's not really a feature of vb.net rather than .Net framework, and the
same applies for C#.

System.dll gets added automatically because ALL .Net programs use it.
There is a huge difference in compiler references from 1.1 to 2.0 and the
compiler in 2.0 seems to recognize what dll to include. For instance, the
code below will compile under 2.0 but not 1.1, using the command line "vbc
code.vb"

Imports System.Drawing

Class Test

Shared Sub Main()

Dim b as new Bitmap(10, 10)

End Sub

End Class

In .Net 1.1 you would need "vbc /reference:System.Drawing.dll test.vb"

In addition to making life easier with "smart" compilers and namespaces,
there are shortcuts.

There is no such thing as a System.Integer, yet Dim i as Integer will work
fine. Nor is Integer found in any other namespace either, but vb.net asa
few aliases. Integer is an alias for System.Int32 (or possible
System.Int64 on 64-bit systems). C# would use int as an alias for
System.Int32

When you type String, Visual Studio and compilers will browse through a
table of keywords and all referenced namespaces. If it finds String
defined it will use it. If it finds String defined several places it
won't know which one to use. The code below illustrates this with Timer

Imports System.Windows.Forms
Imports System.Timers

Class Test

Shared Sub Main()

Dim t as new Timer()

End Sub

End Class

Since the Timer class is defined in both System.Timers.Timer and
System.Windows.Forms (and they are different timers) you will have to
either remove the wrong namespace, use the fully qualified class name (ie
System.Timers.Timer) or define a new alias (shown below)

Imports System.Windows.Forms
Imports MyTimer = System.Timers.Timer

Class Test

Shared Sub Main()

Dim t as new MyTimer()

End Sub

End Class
Welcome to the wonderful world of .Net Framework :)


On Thu, 12 Oct 2006 19:33:01 +0200, www.douglassdavis.com
<do************@earthlink.netwrote:
>
Morten Wennevik wrote:
>Yes and No,

If you create a notepad file code.vb with a main method you will find
that
Console.WriteLine will cause a compiler error unless you add Imports
System.

Visual Studio automatically adds a few namespaces and references to
common
assemblies depending on what project you create.

However, System.dll is always included when you compile so no need to
add
a reference to it.


Fascinating.

I guess VB.NET tries to hide complexity from you. But, i am curous, at
what point do these namespaces get added? Does the simple fact that
the System.dll is included mean that the IDE automatically knows that a
String is a System.String? Or, is it through a command line option when
it compiles? Through some import code it automatically adds to the
code you write?

I know it works, but I'm just curious, for the VB.NET experts out
there, at what point does the magic happen?

--
http://www.douglassdavis.com


--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 16 '06 #6
Morten Wennevik <Mo************@hotmail.comwrote:
It's not really a feature of vb.net rather than .Net framework, and the
same applies for C#.
No, not quite. While certain *assemblies* are added automatically
(depending on csc.rsp), *namespaces* are never used automatically in
C#. That depends *solely* on the source code.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 16 '06 #7

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

Similar topics

26
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes...
8
by: Corey Lubin | last post by:
someGlobal=1 class Original: def foo(self): # Make use of someGlobal from original import * someGlobal=2
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
9
by: me | last post by:
Hi All, I am new to Classes and learniing the ropes with VB.NET express Here's my question - say I have a want to manage a list of books. Each book has an Author, Title and ISBN Now, I am...
3
by: jason | last post by:
Please pardon my completely lack of understanding on the topic. I have a website I developed with another developer. We are both far from experts in VB.NET and OOP. We developed the site WITHOUT...
5
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like,...
173
by: Zytan | last post by:
I've read the docs on this, but one thing was left unclear. It seems as though a Module does not have to be fully qualified. Is this the case? I have source that apparently shows this. Are...
2
by: tshad | last post by:
I have a .dll that has MyFunctions as a Namespace and Class of FWData. If I have my using statement as: using MyFunctions.FWData Why do I have to set a new variable as: Dim fw = New...
12
by: Nathan Sokalski | last post by:
I have several CustomControls that I have written for my project. However, when I try to compile I recieve the following warning & errors: Warning 32 Could not resolve this reference. Could not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.