PDA

View Full Version : .Net & C# question



mickey
20th November 2006, 10:50
Hi, I need in a loop to rest of division; which one is more efficient?


for (i =0; .....i++) {
//int r;
//Math.DivRem(i+1, 2, out r);
int r = (i + 1) % 2;
if ( r == 0) return i;
}

jacek
20th November 2006, 15:25
According to the docs DivRem() calculated both the quotient and remainder.

If you need only the remainder use %, as division is the most time consuming from all of the basic arithmetic operators.