
Untitled
By: a guest on
Jun 27th, 2012 | syntax:
None | size: 0.70 KB | hits: 9 | expires: Never
Data transfer object with O(1) lookup
public class DTO
{
string name;
int id;
int schoolId;
double value;
}
DtoList.Where(x=>x.name="name" && x.id=1 && x.schoolId=2).First();
struct Key
{
string Name;
int Id;
int SchoolId;
}
class DictionaryObject
{
IDictionary<Key, double> _dict;
public DictionaryObject(IEnumerable<Dto> dtoList)
{
_dict = dtoList.ToDictionary(
o => new Key { Name = o.Name, Id = o.Id, SchoolId = o.SchoolId },
o => o.Value);
}
double GetValue(string Name, int Id, int SchoolId)
{
// if the key exists then...
return _dict[new Key { Name = Name, Id = Id, SchoolId = SchoolId }];
}
...
}