DateTime.Compare()
to compare DateTime
s CS-W1018Invoking the .ToString
method and then using the resultant string
for comparison is not guaranteed to work everytime as the resultant string may not necessarily be the best representation of an entity. Instead, it is recommended that you use appropriate methods based on the entities' types. In case of DateTime
, consider using DateTime.Compare()
to compare 2 DateTime
s.
if (actualDate.ToString() == expectedDate.ToString())
{
// ...
}
if (DateTime.Compare(actualDate, expectedDate) == 0)
{
// ...
}