c# - Get every 100th value in a loop -


is there way make cleaner , not use tempvalue have done here?


update code had logic bug , didn't show i'm doing. i'm doing:

var looptempvalue = noofpackets / 100; for(i=0; < noofpackets; i++) {        \\dostuff      if (i == looptempvalue)     {          looptempvalue = looptempvalue + (noofpackets / 100);          uploadbackgroundworker.reportprogress(pross);     } } 

update final

this how fixed after feedback, thx guys.

if (i % (noofpackets / 100) == 0 && != 0) {      uploadbackgroundworker.reportprogress(pross); } 

if (i % 100 == 0 && != 0) { //your code } 

modulus fantastic checks this.

more on modulus - http://www.vias.org/cppcourse/chap04_01.html

update: added && != 0 0 case being true.

if want use tempvalue instead of hard coding 100, solution:

if (i % tempvalue == 0 && != 0) { //your code } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -