Zayko in the Net

Personal blog of Vitaly Zayko

NAVIGATION - SEARCH

Odd or Even? (C#)

How to quickly determine is given number odd or even? There are several simple methods.

Here is the first one:

 

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

And the second:

 public bool IsEven(int i)
 {
     return (i % 2) == 0;
 }

 

Technorati Tags:

Add comment