Namespaces

  • Thread starter Thread starter Pierre
  • Start date Start date
P

Pierre

Hi

I am trying to understand how namespaces work in VB.NET. The program works
partly, i.e. the first two writeline statements work. With the other ones I
get problems, VB doesn't seem to accept my Imports statements. Can someone
tell me what I am doing wrong is this program?

Imports System

Imports GeefMe = One.Eleven.Gimme ' alias voor class

Imports EenEenEen = One.Eleven ' alias voor namespace

Imports One.Twelve

Namespace One

Namespace Eleven

Public Class Gimme

Public Function GimmeAnA() As String

Return "A"

End Function

End Class

End Namespace

Namespace Twelve

Public Class Gimme

Public Function GimmeA1() As Integer

Return 1

End Function

End Class

End Namespace

End Namespace

Class app

'Module Module1

Shared Sub Main()

Dim a As One.Eleven.Gimme = New One.Eleven.Gimme

Console.WriteLine(a.GimmeAnA)

Dim n As One.Twelve.Gimme = New One.Twelve.Gimme

Console.WriteLine(n.GimmeA1)

Dim b As GeefMe = New GeefMe

Console.WriteLine(b.GimmeAnA)

Dim c As EenEenEen.Gimme = New EenEenEen.gimme

Console.WriteLine(c.GimmeAnA)

Dim d As Gimme = New Gimme

Console.WriteLine(d.GimmeA1)

End Sub

'End Module

End Class
 
Before you can use Import to import a namespace, you must have a reference
to the assembly that contains that namespace. Do you?
 
That's what I finally did and it worked fine. But when I wrote the same code
in C# I didn't had to do that, that's why I was puzzled.
 
Back
Top