Russ,
Rather then ask specifically how to Compare two TimeSpan values I normally
ask how to Compare any two values in .NET.
Values that are comparable in .NET either override Object.Equals for
identity Equals or implement the IComparable interface. Classes that
override Object.Equals or Implement IComparable also normally override the
=, <>, <, <=, >, and >= operators. Unfortunately VB.NET 2002 & 2003 do not
directly support overloaded operators, instead you need to explicitly call
the routine (in the case of = operator the routine is op_Equality, see
"Operator Overloading Usage Guidelines" listed below. VS.NET 2005 (aka
Whidbey, due out later in 2005,
http://lab.msdn.microsoft.com/vs2005/) will
support using & defining overloaded operators.
So in the case of TimeSpan I can simply call TimeSpan.Compare or
TimeSpan.CompareTo to compare TimeSpan Values.
Using Equals, Compare, or CompareTo allows my code to be consistent across
all types, rather then needing to remember what property or properties I
need use for each type. For example, if I had a Person type I can simply
call Person.Compare, rather then needing to remember what set of attributes
(properties) of the Person class. Of course the danger of comparing sets of
attributes/properties is code duplication, by calling Person.Compare the
comparison itself is neatly encapsulated in the Person object. Further the
Compare routine is polymorphic, in that each type has its own Compare... Of
course with VS.NET 2005 we will have overloaded operators so I can simply
use the overloaded operators...
I would not rely on comparing Ticks or other properties as that IMHO is an
"oddball solution", an "Oddball Solution" is when you have two or more
similar constructs (comparing objects) & you do it two or more different
ways (DateTime.Ticks, Person.Name). "Oddball Solution" is a "code smell"
that is identified in "Refactoring to Patterns"
http://www.industriallogic.com/xp/refactoring/.
There was a long discussion a few months back in this group on using =
operators or the Equals method titled "Comparing Empty Value Types" from
about November 17, 2004. See the entire thread starting with:
http://groups-beta.google.com/group/...52a3ff291c3f36
For a list of commonly overloaded Operators & the alternative methods see
"Operator Overloading Usage Guidelines" at:
http://msdn.microsoft.com/library/de...Guidelines.asp
IComparable:
http://msdn.microsoft.com/library/de...ClassTopic.asp
Object.Equals:
http://msdn.microsoft.com/library/de...ualsTopic1.asp http://msdn.microsoft.com/library/de...lsOperator.asp
Hope this helps
Jay
"Russ Green" <ma****@SPAMrussgreen.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| How does this:
| public TimeSpan Timeout
| {
| get { return timeout; }
| set
| {
| timeout = value;
| if(timeout < licenseTimeout)
| licenseTimeout = timeout;
| }
| }
| private TimeSpan timeout = TimeSpan.FromMinutes(10);
|
| Convert to VB.NET when in VB.NET Opertor '<' is not defined for types
| 'Sysem.TimeSpan' and System.TimeSpan'
|
|
| TIA
|
| Russ
|
|