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.