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
Post a Comment