I am a beginner programmer and feel like I am repeating code(DownloadFiles()
) as in the below example:
var files = DownloadFiles();
var retryCount = 0;
while (files == null && retryCount < 3)
{
retryCount++;
Console.WriteLine("Retrying {0} time", retryCount);
files = DownloadFiles();
}
My application is basically downloading files via a HttpWebrequest` and is supposed to retry the download 3 times if no files are retrieved.
I need your expert opinion here:
I am repeating code with DownloadFiles()
Could this snippet of code be written more efficiently?
This may seem trivial but I want to develop good programming practices.
do...while
loop