Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJorge Kalil
1,832 Pointswhy is System.DateTime.DaysInMonth() a static method and System.DateTime.AddDays() an instance method?
Also Also System.Math.what returns the larger of two numbers?
2 Answers
Steven Parker
231,268 PointsThese two functions are implemented to suit their parameters and purpose.
You might want to refer to the documentation pages for System.DateTime.DaysInMonth() and System.DateTime.AddDays().
You can see that DaysInMonth takes two integer arguments and returns another integer. Since it makes no direct reference to a DateTime object, it makes sense that it would be implemented as static so it can be invoked without requiring a DateTime instance.
On the other hand, since the purpose of AddDays is to modify an existing DateTime object, it must have a reference to a DateTime object instance. So it makes sense that it would be implemented as an instance method.
Finally, a function that returns the larger of two numbers is commonly named "Max" (short for "maximum").
Jorge Kalil
1,832 PointsThank you!!!