I am trying to compare two DateTime variables which are having the same values in it.
But when I use Equals method it returns false which indicates "Not Equal".
My code is :
DateTime date = DateTime.Parse("2/27/2010 1:06:49 PM");
foreach (KeyValuePair<DateTime, List<string>> k in Sample)
{
if (date.Equals(k.Key))
{
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
}
The dictionary Sample contains the following keys :
- 5/8/2018 11:18:00 AM
- 5/8/2018 11:17:46 AM
- 2/27/2010 1:06:49 PM
- 5/8/2018 11:18:08 AM
The third key value is same as the comparing value.
And for all the key I get no as output.
Can anyone explain why it is happening like this ?