Does anyone know how to create a shared dictionary object?

D

DippyDog

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://
www.hanselman.com/blog/CommentView.aspx?guid=7df37316-2408-404a-a7f9-89fafe19e082#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!
 
C

Cor Ligthert[MVP]

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
 
C

Cor Ligthert [MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top