469,572 Members | 1,674 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

initialize a complex constant in a class

Hi,

I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?

thanks!
ibiza

Feb 22 '06 #1
10 1407


Add a shared variable to hold the dictionary and populate it in the
class Initializer

e.g.

public class Something

private shared _dict as HashTable

shared sub new()

_dict = new ArrayList
' Add the items to the HashTable
end sub

end class

hth,
Alan.

Feb 22 '06 #2
You could expose this as a shared member initialized in the shared
constructor ?

Patrice

--

"ibiza" <la******@gmail.com> a écrit dans le message de
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?

thanks!
ibiza

Feb 22 '06 #3
thanks! :)

I guess you both said the same thing?

Feb 22 '06 #4
is there a collection class that acts as a bidirectional dictionary?

I mean that if I add the entry (1, 42) in a dictionary, and I then do
dic(1), it will return 42.
but is there a class would return the same, but moreover if I do
dic(42), would return 1?

thanks! :)

Feb 22 '06 #5

Why not use an ArrayList and implement BinarySearch?

ibiza wrote:
is there a collection class that acts as a bidirectional dictionary?

I mean that if I add the entry (1, 42) in a dictionary, and I then do
dic(1), it will return 42.
but is there a class would return the same, but moreover if I do
dic(42), would return 1?

thanks! :)

Feb 22 '06 #6
"ibiza" <la******@gmail.com> schrieb:
I have a class which will be used as a utility class (all its functions
shared, no need to instantiate it, let's say just to calculate things)

It needs a constant dictionary(of char, string) with 46 entries in it,
that is used in all its shared functions. How can I instantiate it
automatically only once, instead of creating it at each function call?


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

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Feb 22 '06 #7
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #8
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #9

use .IndexOf() for that

ibiza wrote:
because I mischose my example lol :\

replace the two ints with strings and here's my situation. Cannot use a
string as an index and implement binary search, can I?

Feb 22 '06 #10
could you please supply a concrete (but simple) example? :S I'm not
following you

thanks a lot!

Feb 22 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Kyle | last post: by
5 posts views Thread by Jim Langston | last post: by
3 posts views Thread by dpriver | last post: by
9 posts views Thread by Greg Buchholz | last post: by
4 posts views Thread by bob | last post: by
6 posts views Thread by nik | last post: by
18 posts views Thread by toton | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.