c# - How to prevent repeating code -


i beginner programmer , feel repeating code(downloadfiles()) in below example:

var files = downloadfiles(); var retrycount = 0;  while (files == null && retrycount < 3) {     retrycount++;      console.writeline("retrying {0} time", retrycount);     files = downloadfiles();        } 

my application downloading files via httpwebrequest` , supposed retry download 3 times if no files retrieved.

i need expert opinion here:

i repeating code downloadfiles()

could snippet of code written more efficiently?

this may seem trivial want develop programming practices.

you not repeating code, encapsulated download logic in method, , looping on method.

bad things have been inline downloadfiles method or unroll while loop.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -