Ross,
| I can understand that it's "canonical" to call shared functions from the
| type, but are there actual advantages to prefer that to calling them from
| the object? Won't it compile the same?
Yes it will compile the same.
However! it can lead to misleading code as its not obvious if you are
operating on the instance specified or on something else.
For example, consider the following:
Imports System.Threading
Dim worker As New Thread
...
worker.Sleep(1000)
Will the current thread or the worker thread go to sleep?
The above code "clearly" states that you want worker to sleep for 1000,
however Thread.Sleep is a shared method, that operates on the "Current"
thread so in actuality the current thread sleeps & not the worker thread!
Likewise: Looking at your code, if I didn't actually know what FromHours
did, I would wonder why you are calling a method on an uninitalized variable
& use that to initialize the variable. As your sample:
dim ts as TimeSpan = ts.FromHours(TimA)
Implies that "ts" is somehow involved in the FromHours method, when it fact
it is not...
Fortunately .NET 2.0 (VB 2005, aka Whidbey
http://lab.msdn.microsoft.com/vs2005/) causes worker.Sleep to be an warning,
so you have a chance to correct the misleading code.
Hope this helps
Jay
"Ross Presser" <rp******@NOSPAMgmail.com.invalid> wrote in message
news:1i******************************@40tude.net.. .
| On Wed, 6 Jul 2005 21:35:28 -0500, Jay B. Harlow [MVP - Outlook] wrote:
|
| > NOTE: MM displays months, while mm displays minutes.
|
| Oops! I knew that; it's just that I usually get bitten by using mm where I
| meant to use MM, and I forgot where mm really belongs.
|
| > FromHours is a shared
| > function its "best" to called from the Type itself (TimeSpan), rather
then a
| > variable theTimeSpan or ts.
|
| I can understand that it's "canonical" to call shared functions from the
| type, but are there actual advantages to prefer that to calling them from
| the object? Won't it compile the same?