I have a Dictionary<DateTime, int>
defined like this:
public Dictionary<DateTime, int> Days;
Each DateTime
is associated to an int
. I'd like to have a function which indicates if there is already a DateTime
with the same day in my dictionary:
public int GetIntFromDate(DateTime date)
{
int i = -1;
if (Days.ContainsKey(date))
{
i= CorrespondanceJoursMatchs[date];
}
return i;
}
This is perfect but I'd like that the ContainsKey
returns true
if there is already a DateTime
with the same Day+Month+Year (without looking at hours/minutes/seconds).
In fact my dictionary shouldn't allow 2 DateTime
index with the same Day/Month/Year.
A solution could be to create a class with only a DateTime
attribute and override GetHashCode
and Equals
, but maybe there's a better solution?