c# - Most efficient way to retrieve one file path from a list of folders -


Assume that I have a list of more than 100 folder paths. I want to recover only one file path from each folder path. Here's the way I'm doing this or plan to do this:

  var files = new list & lt; String & gt; (); Var Directories = Directory Gate Directories ("C: \\ FirstFolder \\ Second Folder \\"); Array.ForEach (Directories, D => Files. Update (Directory.GetFiles (D). FirstOrDefault ()));  

Now, is this the most effective way? Because my program starts this code every time.

If you are using .NET 4.0 then you should do it instead ... < / P>

  var files = directory. Select (x = & gt; directory. Indexed files (x). FirstOver Default ()). ToList ();  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -