473,327 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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://
http://www.hanselman.com/blog/Commen...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!
Jun 27 '08 #1
4 2855
On 2008-06-19, DippyDog <di*******@gmail.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
Jun 27 '08 #2
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" <di*******@gmail.comschreef in bericht
news:16**********************************@y38g2000 hsy.googlegroups.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://
http://www.hanselman.com/blog/Commen...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!
Jun 27 '08 #3
On 2008-06-20, Cor Ligthert[MVP] <no************@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
Jun 27 '08 #4
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" <to*********@comcastXXXXXXX.netschreef in bericht
news:YL******************************@comcast.com. ..
On 2008-06-20, Cor Ligthert[MVP] <no************@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

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marcelo Rizzo | last post by:
I am trying to get the name of a file with a specific extension (tmw) from several different directories. The problem I am having is that the program stops working on the second pass with an run...
2
by: Dot net work | last post by:
Hello, My simple code is here: Public Class MyDictionary Inherits System.Collections.DictionaryBase Private Class MyElement Public Overloads Overrides Function Equals(ByVal obj As Object)...
3
by: tropos | last post by:
(Platform: Solaris with gmake and native Sun C++ compiler) Problem: If I create a shared object (.so file) and load it into a executable, the loader correctly runs constructors of static...
11
by: cj | last post by:
Public Class MyStringLogger Private Shared m_loglock As New Object Public Shared Sub Write(ByVal str As String) SyncLock (m_loglock) Dim sw As New System.io.StreamWriter("c:\validate.log",...
6
by: jzdeng | last post by:
Hi, All I use VS 2005 to create a web service. The web service is used to create a sheared folder. It works fine we I run it from VS 2005. But, when I move it to inetpub, it does not work...
18
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an...
19
by: active | last post by:
The ColorPalette class has no constructor so how does one use it? I define a variable by: Dim cp as ColorPalette but don't know how assign an object to the variable. Thanks in advance
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
11
by: MonkeeSage | last post by:
A quick question about how python parses a file into compiled bytecode. Does it parse the whole file into AST first and then compile the AST, or does it build and compile the AST on the fly as it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.