If I am not wrong, when you use
(int)
it is the same than casting to Int32
Convert.ToInt32(value)
I was running a method with the following code:
public int CurrentAge()
{
// return Convert.ToInt32((DateTime.Now - BirthDay).TotalDays)/365;
return (int)((DateTime.Now - BirthDay).TotalDays)/365;
}
Using this date:
DateTime.ParseExact("13-07-1985", "dd-MM-yyyy",null)
And uncommenting the first line, the output is 30
, but casting with (int) results in 29
. Why is this behaviour?
Reading this post for example:
difference between Convert.ToInt32 and (int)
I understand it should be the same.