initialize a complex constant in a class

  • Thread starter Thread starter ibiza
  • Start date Start date
I

ibiza

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
 
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.
 
You could expose this as a shared member initialized in the shared
constructor ?

Patrice
 
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! :)
 
ibiza said:
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
///
 
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?
 
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?
 
could you please supply a concrete (but simple) example? :S I'm not
following you

thanks a lot!
 
Back
Top