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?




Reply With Quote