Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Can anyone think of a smart way to use the framework classes to test a number and tell me whether it's even or odd?

 

I can test the last character in the number and if it's 0,2,4,6,8 then the number is even. This doesn't sound very smart though.

 

Thanks.

Posted

This code works, but is decidedly average:

 


   Public Function EvenNumber(ByVal Number As Integer) As Boolean

           Dim Result As Integer
           Result = Convert.ToInt32(Number.ToString.Substring(Number.ToString.Length - 1, 1))

           Select Case Result
               Case 0, 2, 4, 6, 8
                   Return True
               Case Else
                   Return False
           End Select

   End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...