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 trialDaniel W
1,341 PointsIs there any way to determine that System.DateTime.AddDays() is static or not without looking it up online?
I just finished watching the tutorial in C# about static methods. There it said that it's easy to determine if a method is static if it fits the template "Class.someMethod()" as opposed to "Object.someMethod()".
In the quiz it asks if System.DateTime.AddDays() is static or not. How should you go about this? You would initially think that it is static, but it's not! However DaysInMonth is a static method.
Is there any way at all to determine if they are static or not without looking it up in the MSDN list of methods for a class?
2 Answers
Steven Parker
231,275 PointsYou'd need to know how a method is used to make that determination. You might not need to see the official documentation, but you would have to have some reference that describes how to apply the method. It could be an example in existing code or an abbreviated API summary.
If the method can be invoked using only the class name, it's static. If it requires an instance of the class, it's not.
Daniel W
1,341 PointsHere's where I'm confused though. Both you and the person in the video says:
"If the method can be invoked using only the class name, it's static." But we can call System.DateTime.AddDays() invoking the class name System and DateTime. Yet this method is NOT static. We didn't create any instance of System or DateTime, or did we?