By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,288 Members | 3,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,288 IT Pros & Developers. It's quick & easy.

TimeSpan.zero

P: n/a
i translate a C# funtion to VB.NET and i have this :

Shared Function isAllDay(ByVal ap As Appointment) As Boolean
Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso
ap.DateEnd.TimeOfDay = TimeSpan.Zero
End Function

Error :
= is not corret

so i try " is TimeSpan.zero"

Error again ?!!!

Nov 24 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"ucasesoftware" <uc***********@hotmail.fr> schrieb
i translate a C# funtion to VB.NET and i have this :

Shared Function isAllDay(ByVal ap As Appointment) As Boolean
Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap
.DateEnd.TimeOfDay = TimeSpan.Zero
End Function

Error :
= is not corret

so i try " is TimeSpan.zero"

Error again ?!!!


Return timespan.equals(ap.DateBegin.TimeOfDay, TimeSpan.Zero) _
AndAlso timespan.equals(ap.DateEnd.TimeOfDay, TimeSpan.Zero)
Or simpler:

Return ap.DateBegin.TimeOfDay.ticks = 0 _
AndAlso ap.DateEnd.TimeOfDay.ticks = 0
Armin
Nov 24 '05 #2

P: n/a

ucasesoftware,
In addition to the other comments.

The C# code is relying on overloaded operators. The = operator is overloaded
in the TimeSpan class to support comparing 2 TimeSpan values.

ap.DateBegin.TimeOfDay is a TimeSpan

TimeSpan.Zero is also a TimeSpan.

The C# compiler is using TimeSpan.op_Equal to compare the two values.
op_Equal is the special name for the overloaded = operator.

As Armin shows in VB 2002 & 2003 you need to use TimeSpan.Equals,
TimeSpan.Compare, or TimeSpan.op_Equals to compare the two values.

Fortunately! (Hurrah!) VB 2005 fully supports overloaded operators so you
can use your code "as is".
NOTE: Be careful with the Equals method & structures, such as TimeSpan, as
Equals overridden from System.Object takes Object parameters & will cause
boxing. I normally offer type safe Equals methods on my structures so as to
avoid this boxing. In the case of TimeSpan.Equals(x, y) there is an overload
that accepts TimeSpans hence avoiding the boxing.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ucasesoftware" <uc***********@hotmail.fr> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
|i translate a C# funtion to VB.NET and i have this :
|
| Shared Function isAllDay(ByVal ap As Appointment) As Boolean
| Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso
| ap.DateEnd.TimeOfDay = TimeSpan.Zero
| End Function
|
| Error :
| = is not corret
|
| so i try " is TimeSpan.zero"
|
| Error again ?!!!
|
Nov 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.