By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

how to populate a static hastable?

P: n/a
How do i populate a static hastable without the need to instantiate the
class? any ideas? Im confused.

class VAErrorMap
{
static Hasttable _ErrorMap = new Hashtable();

public VAErrorMap()
{
//populate has here.. but dont want to!
_ErrorMap.Add(1, "error in user input");
_ErrorMap.Add(2, "error in input file");
//etc etc
}
}

Im trying to figure out a way to populate the variable in class scope so i
dont have to instantiate it. The other way would be a singleton - but i dont
want to do this as a sigleton. I cant think of another way.. maybe its
simple and Im just overlooking something.

Thanks,
Girish
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
class VAErrorMap
{
static Hasttable _ErrorMap = new Hashtable();

static VAErrorMap() // static constructor
{
_ErrorMap.Add(1, "error in user input");
_ErrorMap.Add(2, "error in input file");
//etc etc
}
}

HTH;
Eric Cadwell
http://www.origincontrols.com
Nov 15 '05 #2

P: n/a
cool! are static constructors a new feature in c# or do all oo programming
languages have it?

VB, Java, OOPerl, C++?

thanks,
girish

"Eric Cadwell" <ec******@ns.insight.com> wrote in message
news:OZ****************@TK2MSFTNGP11.phx.gbl...
class VAErrorMap
{
static Hasttable _ErrorMap = new Hashtable();

static VAErrorMap() // static constructor
{
_ErrorMap.Add(1, "error in user input");
_ErrorMap.Add(2, "error in input file");
//etc etc
}
}

HTH;
Eric Cadwell
http://www.origincontrols.com

Nov 15 '05 #3

P: n/a

Hi Girish,

Thank you for posting in the community!

Yes, static construcotr gives you a chance to initialize the CLASS not a
class instance.
Many of the .Net languages have implemented this feature, C# and Managed
C++ both have the Static Construcotr, please refer to:
http://msdn.microsoft.com/library/de...us/csref/html/
vclrfStaticConstructors.asp
http://msdn.microsoft.com/library/de...us/vcmxspec/ht
ml/vcmanagedextensionsspec_19.asp

In VB.net, static is represented as "Shared" key word, it has "Shared
Constructor", which is similiar as the Static Construcotr, please refer to:
http://msdn.microsoft.com/library/de...us/vbls7/html/
vblrfvbspec7_2_2.asp

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.