Odd or Even? (C#)

by Vitaly Zayko 24. February 2010 21:15

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:
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

Code Snippets

Comments are closed

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

About the author

Vitaly Zayko

Senior Software Developer / Team Lead / Product Manager

Moscow, Russia