title: how do I pass the values after each iteration of the loop to a separate variable, or to an array for subsequent use/ use in the loop?
body: <pre><code>public static void Run()
  {
      public static string desktop = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
  
      //List&lt;string&gt; found = new List&lt;string&gt;();
      //MemoryStream memoryone = default;
  
      using (var result = new MemoryStream())
      {
          using (var archive = new ZipArchive(result, ZipArchiveMode.Create, true))
          {
              foreach (string p in found) // List&lt;string&gt; found
              {
                              var pr = archive.CreateEntry(&quot;Found_&quot; + p + &quot;.txt&quot;);
  
                              using (var entryStream = pr.Open())
                              {
                                      memoryone.CopyTo(entryStream); // MemoryStream memoryone
                              }
                          }
                  }
              File.WriteAllBytes(@&quot;found.zip&quot;, result.ToArray());
      }
  
      foreach (string path in Paths.sWPaths)
      {
          List&lt;string&gt; my = new List&lt;string&gt; { &quot;qw&quot;, &quot;er&quot;, &quot;ty&quot;, &quot;ui&quot;, &quot;op&quot;, &quot;as&quot;, &quot;df&quot;, &quot;gh&quot;, };
                  List&lt;string&gt; found = Directory.EnumerateDirectories(desktop + &quot;//&quot;)
                      .Select(d =&gt; new DirectoryInfo(path).Name).Where(n =&gt; my.Contains(n)).ToList();
                  
                  List&lt;file&gt; Informone = Data.Get(desktop + path);
                  MemoryStream memoryone = new MemoryStream(cUtils.WriteOne(Informone).ToArray());   
      }
  }    
  
  </code></pre>
  <p>how do I pass the VALUES after each ITERATION of the loop to a separate variable, or to an array for later use in the loop? (I warn you right away, I don't need to output the final value of the loop, but the values of each iteration)</p>
  <p>I need to pass the values of &quot;List &lt; string &gt; found&quot; after each iteration to an array or to a variable</p>
  <pre><code>foreach (string path in Paths.sWPaths)
  {
      List&lt;string&gt; my = new List&lt;string&gt; { &quot;qw&quot;, &quot;er&quot;, &quot;ty&quot;, &quot;ui&quot;, &quot;op&quot;, &quot;as&quot;, &quot;df&quot;, &quot;gh&quot;, };
          List&lt;string&gt; found = Directory.EnumerateDirectories(desktop + &quot;//&quot;)               
              Select(d =&gt; new DirectoryInfo(path).Name).Where(n =&gt; my.Contains(n)).ToList();
  }
  </code></pre>
  <p>for use in another cycle</p>
  <pre><code>foreach (string p in found) // List&lt;string&gt; found
  {
         var pr = archive.CreateEntry(&quot;Found_&quot; + p + &quot;.txt&quot;);
  }
  </code></pre>
  <p>I need to pass the values of &quot;MemoryStream memoryone&quot; after each iteration to an array or to a variable</p>
  <pre><code>foreach (string path in Paths.sWPaths)
  {             
        List&lt;file&gt; Informone = Data.Get(desktop + path);
        MemoryStream memoryone = new MemoryStream(cUtils.WriteOne(Informone).ToArray());   //MemoryStream memoryone
  }
  </code></pre>
  <p>for use here</p>
  <pre><code>using (var entryStream = pr.Open())
  {
        memoryone.CopyTo(entryStream); // MemoryStream memoryone
  }
  </code></pre>