I am very curious about this thing
Int32
int addmonths_int = 10;
DateTime.Now.AddMonths(addmonths_int);
Int16
short addmonths_short = 10;
DateTime.Now.AddMonths(addmonths_short);
If we could give Int16
as Parameter in the AddMonths
function and also the month's value can never be more than 12
then why do .NET Framework
uses the month as Int32
and not Int16
...
If is there any culture specific problem in declaring the month as Int16
... !!??!!
I am here thinking that if month
would have been Int16
then it would saved some bit of length 开发者_StackOverflowin some where .. i think Memory Allocation
UPDATE
what would be the suggestion for DateTime.Now.Month property couldn't it be Int16 instead of Int32 ??
IS IT ALL ONE AND THE SAME ??
First of all, it can be more than 12 months. Nothing stops you from calculating the date plus 435345 months.
As for the Int32 choice: Int32 is the native integer data type of 32 bit systems, so it is the most efficient data type to work with.
If we could give Int16 as Parameter in the AddMonths function and also the month's value can never be more than 12 then why do .NET Framework uses the month as Int32 and not Int16...
Why can't you add thirteen months to today and end up with June 25, 2012?
Your assumption is incorrect:
also the month's value can never be more than 12
Even if you were correct, I don't think it would have bought you much using a 16-bit integer instead of a 32-bit one: probably the size of a DateTime object wouldn't change at all.
You can add more than 12 months to a given date using the AddMonths function.
The actual restriction is as follows though;
Months value must be between +/-120000
精彩评论