473,830 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dictionary vs. Array

I have an application where the data access portion will return a value based
on the enum type month passed to it. I was wondering if this should be done
with a hash map (dictionary) or an ordinary Array with the index numbers.

Answers can come be direct, or simple links to data access explanations on
websites or even references to good books about data access and the reason to
use different data types in different situations.

I appreciate any help given or attempted, even if it is simply criticism of
other, unrelated parts of my code.

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.IO;

namespace Data_Access_for _Jackson_Projec t
{
public class STXXXXInput
{
/// <summary>
/// number of rows in the dat file, or the number of individually
corrilated portions
/// of the year.
/// </summary>
static int ST3A = 14;

/// <summary>
/// The number of coefficients + the indexing variable.
/// </summary>
static int ST3B = 5;
double[,] ST3Coefficients = new double[ST3A,ST3B];

public STXXXXInput(str ing location)
{
StreamReader SR = new StreamReader("S T3-2003.dat");

SR.BaseStream.S eek(0, SeekOrigin.Begi n);

char delimeter = ' ';

for (int i = 0; i < ST3A; i++)
{
string[] temp = SR.ReadLine().S plit(delimeter) ;
int j = 0;
int k = 0;
while (j < ST3B)
{
foreach (string s in temp)
{
if (temp[k] != "")
{
ST3Coefficients[i, j] = Convert.ToDoubl e(s);
j++;
}
k++;
}
}
}
}

/// <summary>
/// The time of the flowperiod in the year.
/// </summary>
public enum FlowPeriod : int
{
July = 0,
August = 1,
September1_15 = 2,
September16_30 = 3,
October1_15 = 4,
October16_31 = 5,
November = 6,
December = 7,
January =8,
February = 9,
March = 10,
April = 11,
May = 12,
June = 13
}

/// <summary>
/// Returns the state 3 coefficients along with what type of fit
they describe
/// </summary>
/// <param name="period"></param>
/// <returns></returns>
public double[] GetST3Coefficie nts(FlowPeriod period)
{
double[] periodST3Coeff = new double[ST3B];

for (int i= 0; i < ST3B; i++)
periodST3Coeff[i] = ST3Coefficients[(int)period, i];
return periodST3Coeff;
}
}
}

Jul 25 '05 #1
2 3989

"Ben Enfield" <Be********@dis cussions.micros oft.com> wrote in message
news:E3******** *************** ***********@mic rosoft.com...
I have an application where the data access portion will return a value
based
on the enum type month passed to it. I was wondering if this should be
done
with a hash map (dictionary) or an ordinary Array with the index numbers.


I would go with direct array indexes as long as the enum won't change. If
the enum might change to the point where you won't have sequential values,
go with a dictionary.
Jul 26 '05 #2
Thank you for using your time to overview my code

"Daniel O'Connell [C# MVP]" wrote:

"Ben Enfield" <Be********@dis cussions.micros oft.com> wrote in message
news:E3******** *************** ***********@mic rosoft.com...
I have an application where the data access portion will return a value
based
on the enum type month passed to it. I was wondering if this should be
done
with a hash map (dictionary) or an ordinary Array with the index numbers.


I would go with direct array indexes as long as the enum won't change. If
the enum might change to the point where you won't have sequential values,
go with a dictionary.

Jul 26 '05 #3

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

Similar topics

2
5315
by: Ryan Malone | last post by:
Passing Dictionary object byref Ive created an ASP class that uses a dictionary object which is filled from a recordset. It passes the object to the propterty of another ASP class byref: Public Property Let dicReplaceVars(byref vdicReplaceVars) set p_ReplaceVars = vdicReplaceVars End Property
9
9996
by: What-a-Tool | last post by:
Dim MyMsg Set MyMsg = server.createObject("Scripting.Dictionary") MyMsg.Add "KeyVal1", "My Message1" MyMsg.Add "KeyVal2", "My Message2" MyMsg.Add "KeyVal3", "My Message3" for i = 1 To MyMsg.Count Response.Write(MyMsg.Item(i)) next
2
3426
by: jg | last post by:
I was trying to get custom dictionary class that can store generic or string; So I started with the example given by the visual studio 2005 c# online help for simpledictionay object That seem to miss a few things including #endregion directive and the ending class } Is there not a simple way like in dotnet vb? I managed to get the sample to code to this:
3
2523
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a sqlite3 database table. Here's the context: The OMR card reader sends a stream of 69 bytes over the serial line; the last byte is a carriage return ('\r') indicating the end of record. Three pairs (in specific positions at the beginning of the...
1
11306
by: Matt Kemmerer | last post by:
I'm trying to return a HashTable froma WebMethod. This fails with a not supported method because HashTable implements IDictionary. What I'm doing right now instead is stuffing my data into a DataSet and then extracting my data from the DataSet on the other side. What I want to know is this: What is the easiest way to return something similar to an associative array (HashTable) from a web service.
20
34167
by: Gustaf | last post by:
This is two questions in one really. First, I wonder how to convert the values in a Dictionary to an array. Here's the dictionary: private Dictionary<Uri, Schemaschemas = new Dictionary<Uri, Schema>(); Uri is the System.Uri class, and Schema is a class I made. Now, I want the class where this Dictionary is contained to have a property that returns all the values in this Dictionary. Like such: public Schema Schemas
2
5903
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the dictionary essentially creates the following array: Key Value
18
4299
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've a question regarding dictionaries. I have an array elements that I created, and I'm trying to sort those elements into various sections. Here's the template of my data type. DT { int nSize; ...
1
4174
by: GVDC | last post by:
Example server-side JavaScript Web script, Dictionary class //Dictionary class, hash array unlimited length configurable speed/efficiency // printf("<html><body>"); printf("<b>Creating dictionary</b><br\n>"); var dictobj = new Dictionary(5); //dictionary class
8
8004
by: Bob Altman | last post by:
Hi all, I'm trying to do something that should be really easy, but I can't think of an obvious way to do it. I have a dictionary whose value is a "value type" (as opposed to a reference type -- in this case, a Boolean): Dim dic As New Dictionary(Of Int32, Boolean) dic(123) = True I want to set all of the existing entries in the dictionary to False. The
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
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
10491
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
10526
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
10206
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...
1
7746
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5617
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
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.