c# - Using a Stopwatch based Func as loop control variable -


trying use func<bool> loop control variable follows seems upset resharper. given following stopwatch:

var executiontimestopwatch = new stopwatch(); executiontimestopwatch.start(); 

this raises "loop control variable never updated inside loop" warning:

func<bool> muststop = () => executiontimestopwatch.elapsedmilliseconds < timeout_milliseconds; while (!muststop()) // -> function call {     // ... } 

however, doesn't:

func<bool> muststop = () => executiontimestopwatch.elapsedmilliseconds < timeout_milliseconds; var k = false;      // -> declaration while (!k)          // -> used loop control {     k = muststop(); // -> explicit update     // ... } 

i don't understand how result of execution of these codes different; muststop() depends on stopwatch should evaluate differently each time called.

am missing something?

am missing something?

no, both code blocks not different. in fact compiler optimize second block remove variable k in cases when compiled release mode.

resharper not prove loop variable changed inside loop since happens in method. resharper isn't clever enough find whether muststop delegate may return different value when called multiple times.

you ignore warning or suppress in case.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -