Check if an int value is an Even or Odd Value in CSharp

Description

The following code shows how to check if an int value is an Even or Odd Value.

Example


using System;/*from  ww w  .jav  a  2s. c  o m*/
using System.Data;


class Class1{
        static void Main(string[] args){
           Console.WriteLine(IsEven(0));
           Console.WriteLine(IsEven(3));
           Console.WriteLine(IsOdd(2));
           Console.WriteLine(IsOdd(1));

        }
    public static bool IsEven(int intValue)
    {
      return ((intValue & 1) == 0);
    }

    public static bool IsOdd(int intValue)
    {
      return ((intValue & 1) == 1);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var