473,804 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concise loading of data into a hashtable ?

Hello,

I am converting an app from JavaScript to ASP.NET

I have the following JavaScript 'associative array'. Is there a
concise way to create an analogous structure in .NET Framework using
c# or VB.NET? I don't want to use JScript.

consFin =
{2:'m',4:'n',6: 'ng',8:'r',10:' l',12:'kh',14:' k',16:'s',18:'h l',19:'tl',20:' s
h'};

The amount of data is tiny and I have no wish to store it in the
database. Likewise, I don't really want to use a pile of
hashtable.add() statements to put the data to the hashtable. There are
another 6 arrays of similarly sized data and 3 of them are associative
arrays too.

I could put this into 2-D arrays and have the data read into the
hashtable but I would have to store the keys (numbers) as strings (and
convert them, or not, to numbers) for my hashtable. Is this the most
sensible solution?

TIA.
Nov 21 '05 #1
2 1374

"mark4asp" <ma************ ****@ntlworld.c om> wrote in message
news:k2******** *************** *********@4ax.c om...
Hello,

I am converting an app from JavaScript to ASP.NET

I have the following JavaScript 'associative array'. Is there a
concise way to create an analogous structure in .NET Framework using
c# or VB.NET? I don't want to use JScript.

consFin =
{2:'m',4:'n',6: 'ng',8:'r',10:' l',12:'kh',14:' k',16:'s',18:'h l',19:'tl',20:' s
h'};

The amount of data is tiny and I have no wish to store it in the
database. Likewise, I don't really want to use a pile of
hashtable.add() statements to put the data to the hashtable. There are
another 6 arrays of similarly sized data and 3 of them are associative
arrays too.

I could put this into 2-D arrays and have the data read into the
hashtable but I would have to store the keys (numbers) as strings (and
convert them, or not, to numbers) for my hashtable. Is this the most
sensible solution?


I would probably code a couple of static arrays and add them to a hashtable
at load time.

something like this

int[] keys = {2,4,6,8,10};
string[] values = { "a", "b", "c", "d" ,"e"};
Hashtable t = new Hashtable();
for (int i=0;i<keys.Leng th;i++)
{
t.Add(keys[i],values[i]);
}

David
Nov 21 '05 #2
On Tue, 28 Sep 2004 08:47:08 -0500, "David Browne" <davidbaxterbro wne
no potted me**@hotmail.co m> wrote:

"mark4asp" <ma************ ****@ntlworld.c om> wrote in message
news:k2******* *************** **********@4ax. com...
Hello,

I am converting an app from JavaScript to ASP.NET

I have the following JavaScript 'associative array'. Is there a
concise way to create an analogous structure in .NET Framework using
c# or VB.NET? I don't want to use JScript.

consFin =
{2:'m',4:'n',6: 'ng',8:'r',10:' l',12:'kh',14:' k',16:'s',18:'h l',19:'tl',20:' s
h'};

The amount of data is tiny and I have no wish to store it in the
database. Likewise, I don't really want to use a pile of
hashtable.add() statements to put the data to the hashtable. There are
another 6 arrays of similarly sized data and 3 of them are associative
arrays too.

I could put this into 2-D arrays and have the data read into the
hashtable but I would have to store the keys (numbers) as strings (and
convert them, or not, to numbers) for my hashtable. Is this the most
sensible solution?


I would probably code a couple of static arrays and add them to a hashtable
at load time.

something like this

int[] keys = {2,4,6,8,10};
string[] values = { "a", "b", "c", "d" ,"e"};
Hashtable t = new Hashtable();
for (int i=0;i<keys.Leng th;i++)
{
t.Add(keys[i],values[i]);
}

David


I needed to use a SortedList not a HashTable. eg.

Dim AconsFin(,) As String =
{{"2","m"},{"4" ,"n"},{"6","ng" },{"8","r"},{"1 0","l"},{"12"," kh"},{"14","k"} ,{"16","s"},{"1 8","hl"},{"19", "tl"},{"20","sh "}}
Dim consFin As New SortedList()

Load_SortedList (AconsFin, consFin)
Show_SortedList (consFin)

Sub Load_SortedList (ary, ht)
For i As Integer = 0 To UBound(ary, 1)
ht.Add(CInt(ary (i , 0)), ary(i , 1))
Next
End Sub

Sub Show_SortedList (ht As SortedList)
Dim hEnum As IDictionaryEnum erator = ht.GetEnumerato r()
Dim str As String
While hEnum.MoveNext( )
str += hEnum.Key.toStr ing() & " : " &
hEnum.Value.toS tring() & vbCrLf
End While
txtEncounter.te xt = str
End Sub

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1292
by: Kevin | last post by:
Hi, I am wondering if I use a hashtable instead of a dataset to hold data in my app will have less overhead and better performance? I am really looking for a data container where I can use a key to retrieve the data (rather not use a 2-dimensional array). Thanks
4
2578
by: Jack | last post by:
Hi, I have a hashtable that I need to pass around to different Business Objects. My question is it better to pass it and make a locale hashtable variable and set it equal to the passed hashtable or should I pass it and not worry about it? Thanks
8
6318
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. Is there a document, or can some one list those types that are not serializable and the syntax for converting them? Thanks
6
1904
by: VidalSasoon | last post by:
I have a singleton class that I want to only contain a hashtable. I want to be able to modify this hashtable at will. The problem I am having is each time I try to update the data using the "SetState" method, "_Instance" keeps on getting reset. I have a hard time grasping the idea how a singleton just holds the data... anyway, here's my test code for console if anyone can help. V.
2
1403
by: mark4asp | last post by:
Hello, I am converting an app from JavaScript to ASP.NET I have the following JavaScript 'associative array'. Is there a concise way to create an analogous structure in .NET Framework using c# or VB.NET? I don't want to use JScript. consFin = {2:'m',4:'n',6:'ng',8:'r',10:'l',12:'kh',14:'k',16:'s',18:'hl',19:'tl',20:'s
11
3626
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a million lines. b) I need to store the contents into a unique hash. c) I need to then sort the data on a specific field. d) I need to pull out certain fields and report them to the user.
7
3135
by: Leszek Taratuta | last post by:
Hello, I need a kind of lightweight data structure known as "associative array". It will store a few values that I need to access using textual keys. The Hashtable is too heavy for me. I also need to serialize data to Session state or View State (in ASP.NET). I think there must be a class in .NET I can use. What collection should I use?
2
5516
by: andrewcw | last post by:
Typically I get a DictionaryEntry from a foreach when walking a Hashtable. My impression is that the foreach returns one item of the hash. One of my commonly used functions received takes a DictionaryEntry as a parameter. In several instances I dont want to recreate a foreach item. but this code to create the dictionaryEntry did not work: eg: Hashtable hTableProcedureTables = new Hashtable();
0
2207
by: speedcoder | last post by:
hi all, i'm stumped. my applet used to load images over the network. (it was actually designed by someone else.) yes, the applet used to load each image file independently over the network and incurred a network hit per image file. i wanted to avoid the overhead of a separate network connection for each image file, so i bundled all the images into the JAR file. yet, somehow, the loading time for the applet is slower now! i'm totally...
1
2013
by: icfai | last post by:
hi friends.... I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet. for that it is required to load that assembly whose sub-classes are required to be loaded into the list box after pressing dot. for example in the code given below i have given the path of System.dll assembly file, now all the sub class of System.Data are automatically...
0
9705
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10568
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
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 we have to send another system

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.