473,383 Members | 1,855 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,383 software developers and data experts.

how to populate a static hastable?

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
3 3496
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
0
by: Cliff | last post by:
Can someone tell me ...show me how to I would go about creating a Hastable in a HashTable. Say I have items A B C D. I want to be able to call item A the key, and it will give me back B C and D....
3
by: Ajay | last post by:
I have a global hashtable instance in my application which is accessed by threads within that application for readonly access. Do I need to synchronize the hashtable if readonly access is required?...
1
by: Grant Hammond | last post by:
I have a callback function that populates a listbox with a list of file names in a folder. This code came from Terry Kreft/Dev Ashish some years ago. I now want to add another column to the list...
2
by: PABLO | last post by:
Hello I have a Hastable, which I need to order it by value and not by key. Regards
3
by: nevin | last post by:
Hello all, I've looked on the net and can't seem to find what I need so I must be searching badly or have (another) 'non-problem'. I am simply trying to move the values of a hastable or sorted...
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
1
by: Hal Heinrich | last post by:
Hi, I have a hastable with key/value pairs. I want to iterate thru the collection in descending order by value. What is the 'best practice' for handling this problem? Thanks in advance for...
5
by: RSH | last post by:
I have two HashTables (_CompanyDeductions,_CompanyAccruals) that contain several objects each. I am trying to loop through and print the properties of the objects in the Hashtables: I am trying...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.