0

I understood them to be modules, such as my little one:

Public Module Config
    Public Property ImportSettings As ImportConfig
    Sub New()
        ImportSettings = ImportConfig.Read()
    End Sub
End Module

Yet, I cannot access ImportSettings. I'm told it's not declared, and its value is 'Nothing'.

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 1
    You cannot initialize a module. It cannot be used as a type. – OneFineDay Oct 02 '14 at 04:02
  • 1
    possible duplicate of [Classes vs. Modules in VB.Net](http://stackoverflow.com/questions/881570/classes-vs-modules-in-vb-net) | And here's a bonus link: [google.com?q=vb.net module statement](http://msdn.microsoft.com/en-us/library/aaxss7da.aspx). – Bjørn-Roger Kringsjå Oct 02 '14 at 05:50
  • @OneFineDay - not quite true. You can have a "static constructor" in a module – Matt Wilko Oct 02 '14 at 08:56

1 Answers1

0

Static(C#)/Shared(VB) method/property in a class:

Public Class Config
  Public Shared ReadOnly Property ImportSettings As ImportConfig
    Get
       Return ImportConfig.Read()
    End Get
  End Property
End Class

Usage:

Dim configs = Config.ImportSettings

Since it is Static/Shared we do not need to initialize the Config class.

OneFineDay
  • 9,004
  • 3
  • 26
  • 37