• 0

[C#] Loop break does nothing...just keeps looping...


Question

			XDocument xDoc = XDocument.Load(@"C:\Programs\DRS Corporation\MTG\install_flist.xml");
			var files = from file in xDoc.Descendants("file")
						select new
						{
							Filename = file.Element("Name").Value,
							Folder = file.Element("Directory").Value
						};

			foreach (var file in files)
			{
				fileList.Add(file.Filename, file.Folder);
			}
			foreach (KeyValuePair<string, string> file in fileList)
			{
				upl.DownloadFile("ftp://ftp.couchpotatoheroes.com/public_html/MTG/{xda_set_01B}/" + cPath + "/" + file.Key, @"C:\Program Files\DRS Corporation\MTG\Plugins\" + file.Key, downloadPoolStart);
				System.Diagnostics.Debug.WriteLine("Deleting " + file.Key);
				fileList.Remove(file.Key);
				break;
			}

Any ideas as to why this is? It's weird. It should not be looping once it hits the break; statement.

or it calls the whole function over again I should say.

1 answer to this question

Recommended Posts

  • 0

Is there any point in having that break statement there, only the first run through the loop will complete because you are not doing conditional checking.

You can either remove the foreach... statement as you only seem to allow it to run once, or remove the break statement so the loop with enumerate the dictionary.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.