473,386 Members | 1,702 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,386 software developers and data experts.

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.Collections.Generic;
using System.Text;
using System.IO;

namespace Data_Access_for_Jackson_Project
{
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(string location)
{
StreamReader SR = new StreamReader("ST3-2003.dat");

SR.BaseStream.Seek(0, SeekOrigin.Begin);

char delimeter = ' ';

for (int i = 0; i < ST3A; i++)
{
string[] temp = SR.ReadLine().Split(delimeter);
int j = 0;
int k = 0;
while (j < ST3B)
{
foreach (string s in temp)
{
if (temp[k] != "")
{
ST3Coefficients[i, j] = Convert.ToDouble(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[] GetST3Coefficients(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 3962

"Ben Enfield" <Be********@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.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********@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.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
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: ...
9
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...
2
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...
3
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...
1
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...
20
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,...
2
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...
18
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...
1
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...
8
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 --...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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,...
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.