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. 2 1353
"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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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. ...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: 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: 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: 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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |