473,811 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET classes, imports, and namespaces



Is the whole System namespace automatically imported?

Oct 11 '06 #1
6 2474
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************* ********@m7g200 0c...legrou ps.com...
>

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 "subsection s" 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.WriteLi ne 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.netw rote:
>

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.WriteLi ne 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:Syste m.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.T imer 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.T imer) or define a new alias (shown below)

Imports System.Windows. Forms
Imports MyTimer = System.Timers.T imer

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.netw rote:
>
Morten Wennevik wrote:
>Yes and No,

If you create a notepad file code.vb with a main method you will find
that
Console.WriteL ine 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.comwro te:
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.co m>
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
29645
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 were still an option. However, I am coming up dry looking for information on how to do this, and the most recent references I am able to find to nested classes in PHP are dated 2003. And they all say the same thing: sorry, can't do that.
8
6110
by: Corey Lubin | last post by:
someGlobal=1 class Original: def foo(self): # Make use of someGlobal from original import * someGlobal=2
45
3632
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 themselves are an exception to this), and 'bootstrap' your program by instantiating a single application object in main(), would that place any limitations on what you could accomplish with your program? Are there any benefits to doing things that...
9
2030
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 used to using Arrays so I would normally do something like this: Set an array up during the init routine (called from form_load) say of
3
1596
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 VS.NET, compiling vb.net code into a common dll in the bin directory off the root of the website. That one vb code creates a namespace we import in all of our ASP.NET code. Compiling was done fromt he command line use vbc.exec. The site works...
5
1661
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, keeps stuff apart. If I do that, I usually name the .py file to the same as the class in it. File: Foo.py *********************** class Foo:
173
5741
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 modules left-over from VB6, and not much used anymore? It seems that it is better to require Imports or use fully qualified names for functions in other classes/modules, but a Module doesn't require this, cluttering the global namespace. It seems...
2
1124
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 MyFunctions.FWData(10)
12
2047
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 locate the assembly "nathansokalski_com_test, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors....
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.