even - odd numbers

What is the function in .NET to distiguish between even and odd numbers?
LVL 5
thenrichAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can use the Mod function to determine if a number is even like this:

    Private Function isEven(ByVal number As Integer) As Boolean
        Return (number Mod 2) = 0
    End Function

~IM
0
 
Arthur_WoodCommented:
you can write your own, using the MOD operator

    Private Function OddEven(ByVal MyNumber As Integer) As String

        If MyNumber Mod 2 = 0 Then
             Return "Even"
       Else
             Return "Odd"
     End If
End Function


which you could use like this ( add a TextBox, Label and Button to a Form):

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = " Is " & OddEven(TextBox1.Text)
    End Sub
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.