473,405 Members | 2,310 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,405 software developers and data experts.

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:'hl',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 16 '05 #1
2 1389

"mark4asp" <ma****************@ntlworld.com> 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:'hl',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.Length;i++)
{
t.Add(keys[i],values[i]);
}

David
Nov 16 '05 #2
On Tue, 28 Sep 2004 08:47:08 -0500, "David Browne" <davidbaxterbrowne
no potted me**@hotmail.com> wrote:

"mark4asp" <ma****************@ntlworld.com> 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:'hl',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.Length;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"},{"10","l "},{"12","kh"},{"14","k"},{"16","s"},{"18","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 IDictionaryEnumerator = ht.GetEnumerator()
Dim str As String
While hEnum.MoveNext()
str += hEnum.Key.toString() & " : " &
hEnum.Value.toString() & vbCrLf
End While
txtEncounter.text = str
End Sub

Nov 16 '05 #3

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

Similar topics

4
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...
4
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...
8
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. ...
6
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...
11
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...
7
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...
2
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...
2
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...
0
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...
0
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,...
0
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...

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.