title: Parallel.ForEach with tuple return c#
body: <p>Based on this <a href="http://reedcopsey.com/2010/01/22/parallelism-in-net-part-4-imperative-data-parallelism-aggregation/" rel="nofollow noreferrer">example</a> I'm trying to make a parallel foreach with tuple return.</p>
  
  <pre><code>double min = double.MaxValue;
  
  object syncObject = new object(); 
  Parallel.ForEach(collection, () =&gt; double.MaxValue, (item, loopState, 
      localState) =&gt;
      {
          double value = item.PerformComputation();
          return System.Math.Min(localState, value);
      },
      localState =&gt;
      {
          lock(syncObj)
              min = System.Math.Min(min, localState);
      }
  );
  
  Console.Write(min + "\n");
  </code></pre>
  
  <p>The above code works fine but in my occasion(correct minimum value) but i don't want to output the minimum value but the 'name' of that value so i tried something like this:</p>
  
  <pre><code>double min = double.MaxValue;
  string minName = "";
  
  object syncObject = new object(); 
  Parallel.ForEach(collection, () =&gt; Tuple.Create(double.MaxValue, ""), (item, 
      loopState, localState) =&gt;
      {
          double value = PerformComputation(item.Item1.Value);
          string name = item.Item1.Key;
  
          return //helpHere
      },
      localState =&gt;
      {
          lock(syncObj)
              min = //help here
              minName = //help here
      }
  );
  
  Console.Write(minName + "\n");
  </code></pre>
  
  <p>Tried couple things that didn't work. Also I've read <a href="https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-write-a-parallel-foreach-loop-with-thread-local-variables" rel="nofollow noreferrer">microsoft's example</a> without luck. 
  Any help appreciated. </p>