Does anyone know how to create a shared dictionary object?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DippyDog

    Does anyone know how to create a shared dictionary object?

    I have a list of key-value pairs that should be shared, but I don't
    know how to code it. The trick for me is how to populate it when it's
    instantiated.

    Herfried got so close to showing me how in a post some while back with
    this code...

    Private Shared m_Bla As Dictionary = New Dictionary(...)

    Private Shared ReadOnly Property Bla() As Dictionary
    Get
    Return m_Bla
    End Get
    End Property

    But that doesn't show me how to put anything into the list. I'm on the
    verge of doing it in C# since Scott Hanselman's recent post (http://
    https://www.hanselman.com/blog/Comme...2#commentstart)
    showed populating a dictionary object upon instantiation. The same
    post, actually, is the same that's motivating me to clean up my code a
    bit, namely using a dictionary to map things instead of a big select
    (or "switch" in his post).
    Thanks!
  • Tom Shelton

    #2
    Re: Does anyone know how to create a shared dictionary object?

    On 2008-06-19, DippyDog <dippykdog@gmai l.comwrote:
    I have a list of key-value pairs that should be shared, but I don't
    know how to code it. The trick for me is how to populate it when it's
    instantiated.
    >
    Herfried got so close to showing me how in a post some while back with
    this code...
    >
    Private Shared m_Bla As Dictionary

    Shared Sub New ()
    m_Bla = new Dictionary()
    m_Bla.Add("one" , 1)
    m_Bla.Add("Two" , 2)
    ...
    End Sub
    Private Shared ReadOnly Property Bla() As Dictionary
    Get
    Return m_Bla
    End Get
    End Property
    HTH
    --
    Tom Shelton

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Does anyone know how to create a shared dictionary object?

      Dippy Dog,

      You cannot instance a shared class or its equivalent a module.

      The methods exist as everything simple constantly in your program in memory
      as long as your program runs, so you can create a method in the shared class
      or module which you use at startup to fill the dictionary.

      Cor

      "DippyDog" <dippykdog@gmai l.comschreef in bericht
      news:16271f42-81a8-4d17-946d-1804da51571d@y3 8g2000hsy.googl egroups.com...
      >I have a list of key-value pairs that should be shared, but I don't
      know how to code it. The trick for me is how to populate it when it's
      instantiated.
      >
      Herfried got so close to showing me how in a post some while back with
      this code...
      >
      Private Shared m_Bla As Dictionary = New Dictionary(...)
      >
      Private Shared ReadOnly Property Bla() As Dictionary
      Get
      Return m_Bla
      End Get
      End Property
      >
      But that doesn't show me how to put anything into the list. I'm on the
      verge of doing it in C# since Scott Hanselman's recent post (http://
      https://www.hanselman.com/blog/Comme...2#commentstart)
      showed populating a dictionary object upon instantiation. The same
      post, actually, is the same that's motivating me to clean up my code a
      bit, namely using a dictionary to map things instead of a big select
      (or "switch" in his post).
      Thanks!

      Comment

      • Tom Shelton

        #4
        Re: Does anyone know how to create a shared dictionary object?

        On 2008-06-20, Cor Ligthert[MVP] <notmyfirstname @planet.nlwrote :
        Dippy Dog,
        >
        You cannot instance a shared class or its equivalent a module.
        >
        The methods exist as everything simple constantly in your program in memory
        as long as your program runs, so you can create a method in the shared class
        or module which you use at startup to fill the dictionary.
        >
        Cor
        >
        That's what Shared constructor's (Shared Sub New) is for :)

        --
        Tom Shelton

        Comment

        • Cor Ligthert [MVP]

          #5
          Re: Does anyone know how to create a shared dictionary object?

          Tom,

          I was in doubt, did not know if you had misread it, or that I was not aware
          that the Sub New could be used as that. I was sure that you would reply as
          it was like that.

          :-)

          Cor


          "Tom Shelton" <tom_shelton@co mcastXXXXXXX.ne tschreef in bericht
          news:YLudneY9VY J-oMbVnZ2dnUVZ_qP inZ2d@comcast.c om...
          On 2008-06-20, Cor Ligthert[MVP] <notmyfirstname @planet.nlwrote :
          >Dippy Dog,
          >>
          >You cannot instance a shared class or its equivalent a module.
          >>
          >The methods exist as everything simple constantly in your program in
          >memory
          >as long as your program runs, so you can create a method in the shared
          >class
          >or module which you use at startup to fill the dictionary.
          >>
          >Cor
          >>
          >
          That's what Shared constructor's (Shared Sub New) is for :)
          >
          --
          Tom Shelton

          Comment

          Working...