Hi,
I have a class which contains all my constant values such as;
public static readonly string[] strStringOps = {"Equals","Not
Equals","Contains"};
The above nicely assigns the values into the string array. However
I'm looking for a way of achieving the same results whilst using a
hashtable; for example
public static hashtable myhash = new hashtable(idictionary)
however I can't find a way of defining all the the key pairs and
passing that into the above e.g.
public static idictionary mydict = {"key","pair","key1","pair1"};
public static hashtable myhash = new hashtable(mydict)
can anyone help, suggest an alternative way, or am I really stuck with
calling
public static idictionary mydict = new hashtable();
myhash.add("foo","bar");
thanks 3 5412
"hiddenhippo" <re*****@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
I have a class which contains all my constant values such as;
public static readonly string[] strStringOps = {"Equals","Not
Equals","Contains"};
The above nicely assigns the values into the string array. However
I'm looking for a way of achieving the same results whilst using a
hashtable; for example
public static hashtable myhash = new hashtable(idictionary)
however I can't find a way of defining all the the key pairs and
passing that into the above e.g.
public static idictionary mydict = {"key","pair","key1","pair1"};
public static hashtable myhash = new hashtable(mydict)
can anyone help, suggest an alternative way, or am I really stuck with
calling
public static idictionary mydict = new hashtable();
myhash.add("foo","bar");
In C# version 2.0, you are stuck with the .Add method, but in C# version
3.0, you can make use of Object and Collection Initializers to initialize a
collection (which in your case should probably be a Dictionay<string,string>
rather than a Hashtable) in the declaration line.
See http://msdn2.microsoft.com/en-us/lib...cs3spec_topic5
hiddenhippo wrote:
Hi,
I have a class which contains all my constant values such as;
public static readonly string[] strStringOps = {"Equals","Not
Equals","Contains"};
The above nicely assigns the values into the string array. However
I'm looking for a way of achieving the same results whilst using a
hashtable; for example
public static hashtable myhash = new hashtable(idictionary)
however I can't find a way of defining all the the key pairs and
passing that into the above e.g.
public static idictionary mydict = {"key","pair","key1","pair1"};
public static hashtable myhash = new hashtable(mydict)
can anyone help, suggest an alternative way, or am I really stuck with
calling
public static idictionary mydict = new hashtable();
myhash.add("foo","bar");
thanks
There's a KeyValuePair class you might get away with using in an array
and/or wrapping that in a list:
private static KeyValuePair<string,string>[] myKvP = {
new KeyValuePair<string,string>("key1", "value1"),
new KeyValuePair<string,string>("key2", "value2"),
new KeyValuePair<string,string>("key3", "value3"),
new KeyValuePair<string,string>("key4", "value4")};
public static List<KeyValuePair<string, string>myList = new
List<KeyValuePair<string, string>>(myKvP);
It really depends on how you want to access it though.
Chris.
hiddenhippo wrote:
Hi,
I have a class which contains all my constant values such as;
public static readonly string[] strStringOps = {"Equals","Not
Equals","Contains"};
The above nicely assigns the values into the string array. However
I'm looking for a way of achieving the same results whilst using a
hashtable; for example
public static hashtable myhash = new hashtable(idictionary)
however I can't find a way of defining all the the key pairs and
passing that into the above e.g.
public static idictionary mydict = {"key","pair","key1","pair1"};
public static hashtable myhash = new hashtable(mydict)
can anyone help, suggest an alternative way, or am I really stuck with
calling
public static idictionary mydict = new hashtable();
myhash.add("foo","bar");
thanks
Add a static constructor to your class and populate the list there.
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan Cernat |
last post by:
Hi there,
A few threads I had a little chat about default values. I am starting this
thread because I want to hear more opinions about the default values of
function parameters. Some say they...
|
by: BigMan |
last post by:
Why does an emtpy class require an explicit default ctor in order to
initialize const objects of that type:
class EmptyClass
{
};
class EmptyClass2
{
EmtpyClass2( ) { }
|
by: gregory.petrosyan |
last post by:
Hello everybody!
I have little problem:
class A:
def __init__(self, n):
self.data = n
def f(self, x = ????)
print x
All I want is to make self.data the default argument for self.f(). (I
|
by: Nick Vaughan |
last post by:
While running some long term tests on our Broadcast SDK one of our
thread dropped out because an exception had been thrown:
Exception: System.ArgumentOutOfRangeException
Message: Load factor...
|
by: Edward Diener |
last post by:
Given
value class X
{
public:
// Not allowed: X():i(100000),s(10000) { }
// Allowed
void InitializeDefaults() { i = 100000; s = 10000; }
private:
int i;
| |
by: syntego |
last post by:
We commonly use triggers to log changes to our main tables to
historical log tables.
In the trigger, we create a concatenated string of the old values by
casting them as follows:
...
|
by: PAzevedo |
last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from
multiple threads, now the Hashtable object is thread safe for reading,
but not for writing, so I lock the object every time I...
|
by: Zytan |
last post by:
I have a struct constructor to initialize all of my private (or public
readonly) fields. There still exists the default constructor that sets
them all to zero. Is there a way to remove the...
|
by: JohnQ |
last post by:
Are a default constructor, destructor, copy constructor and assignment
operator generated by the compiler for a struct if they are not explicitely
defined?
I think the answer is yes, because...
|
by: hiddenhippo |
last post by:
Hi,
I have a class which defines and instantiates all my global
application level variables; for example,
namespace Constants
{
public sealed class UserActionIdAbbr
{
public static string...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |