471,344 Members | 1,006 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 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 3884

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ryan Malone | last post: by
9 posts views Thread by What-a-Tool | last post: by
2 posts views Thread by jg | last post: by
1 post views Thread by Matt Kemmerer | last post: by
20 posts views Thread by Gustaf | last post: by
18 posts views Thread by =?Utf-8?B?VHJlY2l1cw==?= | last post: by
8 posts views Thread by Bob Altman | last post: by
reply views Thread by Ronak mishra | last post: by

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.