|
-
Jan 6th, 2004, 09:01 AM
#1
Thread Starter
Fanatic Member
Console app without the Imports statement
I am practicing VB.NET and am still a neophyte in the order, though I've done VB from version 4 to 6 for many years now. I was wondering how in one of my programs (a console app) I forgot to include the Imports statement and the compiler did not complain.
For instance,
Code:
Option Strict On
Class zzz
'Properties
Dim j as integer
Shared dim k as integer
Shared Sub Main()
dim a,b as zzz
a = new zzz(10)
a.abc(100)
b = new zzz(20)
b.abc(200)
End Sub 'End of Main
Sub New(i as integer)
System.Console.WriteLine("in new {0} {1} {2}", i , j , k)
j = i
k = i
System.Console.WriteLine("in new {0} {1} {2}", i , j , k)
End Sub 'End of constructor for the zzz class
Sub abc(p as integer)
System.Console.WriteLine("in abc {0} {1}", j , k)
k = p
j = p
End Sub 'End of sub procedure abc
End Class 'End of class zzz
' Guessed Output
'10 0 0
'10 10 10
'10 10
'20 0 100
'20 20 20
'20 20
'Conclusion
'Since the class member k is shared, it is the same accross all instances of the class zzz.
Why is it that the compiler did not complain on not finding the Imports statement where I should have written Imports System since the Console class is a member of the System namespace. Besides, I was writing this in Notepad, so if at all the VS.NET IDE adds namespaces on its own, there was no such possibility in the Notepad environment I was writing code in. What's the secret?
-
Jan 6th, 2004, 09:22 AM
#2
Frenzied Member
It didn't complain because you completely declared the Namespace, Class, Method like this
Code:
System.Console.WriteLine
However, if you had just written this line of code
It would have yelled, because you can't use the Console class without Importing (using in C#) the System namespace.
It can be done either way
VB Code:
'Complete declaration
System.Console.WriteLine
'Or Importing the namespace
Imports System
Console.WriteLine
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jan 6th, 2004, 09:33 AM
#3
Thread Starter
Fanatic Member
Silly me, that was common sense, but I was being careless. I did not write the code but I pasted it from somewhere and guessed the output (I only wrote the footnote to guess the output and the conclusion). So I did not look at the WriteLine function call to see it already had a fully qualified namespace prefixed.
Thanks very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|