title: C# .Net Wait for all threads to complete and get return values
body: <p>I am using the following code to create two threads and wait them to complete:</p>
  
  <pre><code>Task task1 = Task.Factory.StartNew(() =&gt; DoSomething(a, b));
  Task task2 = Task.Factory.StartNew(() =&gt; DoSomething(a, b));
  
  Task.WaitAll(task1, task2);
  </code></pre>
  
  <p>The DoSomething Method returns has a return type of string and when both of the tasks finish I want to use the return value of it.</p>
  
  <p>I tried creating two string variables, and assign them value returned like: </p>
  
  <pre><code>string x, y;
  Task task1 = Task.Factory.StartNew(() =&gt; x = DoSomething(a, b));
  Task task2 = Task.Factory.StartNew(() =&gt; y = DoSomething(a, b));
  </code></pre>
  
  <p>But I get a compile time error that x and y are unassigned, what am I missing here?</p>