title: C# return value inside linq list based on if statement
body: <p><strong>What I have</strong></p>
  
  <p>I have a list, which would execute only when certain conditions are met</p>
  
  <pre><code>var list = data.Where(!t.Area.HasValue || t =&gt; t.Area == response.Area).Select(t =&gt; new Status()
  {
     PK = t.PK,
     Area = t.Area,
     Description = t.Description
     //other stuff
  }).ToList();
  </code></pre>
  
  <p><strong>What I want</strong></p>
  
  <p>This list works fine the way it is, but now I want to modify it slightly. For one of the variables, I want to run an if-else statement, and that variable will be the return result of if-else statement execution</p>
  
  <pre><code>var list = data.Where(!t.Area.HasValue || t =&gt; t.Area == response.Area).Select(t =&gt; new Status()
  {
     PK = t.PK,
     Area = t.Area,
     Description,    //&lt;---------------returns the value of executed if-else statement
                                           //if (t.Area.HasValue) Description = a;
                                           //else Description = b;
     OtherStuff = t.OtherStuff
  }).ToList();
  </code></pre>
  
  <p>My question is: <strong>Where to I place that if-else condition in order to properly execute it?</strong></p>
  
  <p><strong>What I tried</strong></p>
  
  <p>I tried placing if-else statement inside the place of actual variable between two commas.</p>
  
  <p>I tried using temp variable, whose result will be returned, but I don't want to have this temp variable in my list.</p>
  
  <p>I tried having extra conditions inside Where() before I realized it is a set of conditions to actually execute that list.</p>
  
  <p>Searching SO and internet did not get me desired outcomes to try out (hopefully, I was not just using a wrong search criteria).</p>