# Dictionary Structure

I am brand new to dictionaries and coding and am hoping to get some suggestions on how I should structure my dictionary.

I have a collector number which has meters connected to them. Each of the meters have a meter number and a ert number and would like to store both the meter and ert number. There will be a list of meter reading timestamps and values for each of the meters. Also, I would like to be able to select the values by either the ert number or meter number. I have attached the current structure I have for the dictionary but was wondering if this was the best way to format the dictionary. Someone had suggested objects but I have never worked with objects before.

{
Dictionary<Int32, Dictionary<string, Meter>> dictionary = new Dictionary<int, Dictionary<string, Meter>>();

if (!dictionary.ContainsKey(objectID))
{
}

Meter meter = new Meter();
meter.ertNumber = "9480:1";

}

class Meter
{
public String ertNumber { get; set; }
public String meterNumber { get; set; }
public Dictionary<Int32, double> Reading { get; set; }
}

• Dictionaries are fast (O(1)) but not handy if you need to find items by more than one 'key'. If the lists will not be large you'd be better of just using a list of objects (classes) using Linq to find items. I also think that is what that someone meant by 'objects' – Silvermind Apr 16 '13 at 17:30
• That makes sense. I have been thinking about it and I really do not need the objectID and only need either the ert or meter number to reference. The function of the dictionary is to be able to add every meter numbers value at a desired index. I think I will be able to create a dictionary that can use the Meter Number as the key then the value is another dictionary that will have keys from 0-however long the list is and the value as the meter value. – user24194 Apr 16 '13 at 18:44

If you have a collection of Meters and you want to be able to find the ONE based on a property, this is how I would do it:

Create a List of Meters, say l..

List<Meter> l = new List<Meter>();


Then implement Extension methods like so..

public static class MeterExt
{
public static Meter GetByErm(this List<Meter> l, String sErm)
{
Meter r = l.Find(s => s.ertNumber == sErm);

return r;
}

public static Meter Get(this List<Meter> l, String sMeter)
{
Meter r = l.Find(s => s.meterNumber == sMeter);

return r;
}
}


Then you can find your meter like so..

Meter m = l.Get("fsadfa");