473,544 Members | 1,808 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 3968

"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
5287
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
9978
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
3410
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...
3
2504
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...
1
11279
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...
20
34122
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...
2
5861
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
4270
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
4159
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
7967
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...
0
7431
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...
0
7370
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...
0
7779
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...
0
5920
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4924
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...
0
3424
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...
0
3415
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1848
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
0
674
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.