Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain object use; using object before it's constructed 2

Status
Not open for further replies.

cjburkha

Programmer
Jul 30, 2004
76
US
I think I have a fair grip on OOP, but this part of VB.NET has me a bit confused:

Code:
sub Page_Load(sender As Object, e As EventArgs)
dim maxDaysNewMonth as integer =  datetime.DaysInMonth(1996, 2)
response.write(maxDaysNewMonth)
end sub

What confuses me is the datetime method call. My can I use a method of this class, when I havn't created the object yet? Is this an object that is made available to me my the .NET framework somehow? The page somehow makes this object availabe to me, just like the response object? I looked in MSDN, and they don't even call this a class, but rather a structure, but it still has methods.

Does anyone have any insight into this? Any pointers? Links?

I mean, I wouldn't do this:
Code:
dim intStringLength = String("Steve").Length
 
When you look in the online help, if you see the yellow "S" beside a method or property, that indicates that it's a Shared or Static member, and that you call it by using the class name, and not an instance of the class.

People usually write them as a convenience to the class' user -- they're usually methods that perform some utility function that don't affect any stored instance data in the class. XmlConvert is a good example.

When writing your own classes, try not to use them if you can avoid it. A class with all-static member is little better than a kitchen sink.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top