The other suggestions for using a modulus operator certainly work, but I've
always done it with a bitwise operation, since any odd number will have the
low order bit set:
if ( (n & 1) == 0 )
Console.WriteLine( "Odd" );
else
Console.WriteLine( "Even" );
Looked at objectively, the bitwise operation is probably more obscure than
the modulus operation, but to me it has always been one of those common
idioms that every (by which I mean everyone I work with) C programmer has in
common.
"Eps" <ep*@mailinator.com> wrote in message
news:d3**********@domitilla.aioe.org...
I have a for loop and i want to do different things depending on whether
the counter is even or odd.
I know there is probably some really simple math thing that can do this
but my maths is a bit hazy. I did check the MS C# library site but had
no luck.
Any help appreciated.
--
Eps
http://ukcomment.blogspot.com/
A UK political Blog