Dictionary vs. Array

G

Guest

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 = ST3Coefficients[(int)period, i];
return periodST3Coeff;
}
}
}
 
D

Daniel O'Connell [C# MVP]

Ben Enfield said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top