even - odd numbers

Posted on 2004-10-22
Last Modified: 2012-08-13
What is the function in .NET to distiguish between even and odd numbers?
Question by:thenrich
    LVL 85

    Accepted Solution

    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

    LVL 44

    Expert Comment

    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"
                 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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles al…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now