Testing for even and odd number.

jspencer

Regular
Joined
Jan 30, 2003
Messages
81
Location
London, UK
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.
 
This code works, but is decidedly average:

Code:
    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
 
Back
Top