title: Avoiding twice coding, One in if Condition and One in Assignment - C#
body: <p>Here is my sample code:</p>
  
  <pre><code>if (_Timing != target.Split(':')[0] + ": ")
     _Timing = target.Split(':')[0] + ": ";
  </code></pre>
  
  <p>I check if <code>_Timing</code> is not equal to <code>target.Split(':')[0] + ": "</code> then I will assing it to <code>_Timing</code>. I execute this <code>target.Split(':')[0] + ": "</code> two times. I need to avoid it.</p>
  
  <p>another example is this:</p>
  
  <pre><code>if (db.Students.FirstOrDefault(x =&gt; x.Name == "Joe") != null)
     var a = db.Students.FirstOrDefault(x =&gt; x.Name == "Joe");
  </code></pre>
  
  <p>here again, I execute <code>db.Students.FirstOrDefault(x =&gt; x.Name == "Joe")</code> two times. These samples are just some examples. I need to avoid twice coding like these.</p>
  
  <p>I can do this due to answers received:</p>
  
  <pre><code>var splitted= target.Split(':')[0] + ": ";
  if (_Timing != splitted)
     _Timing = splitted;
  </code></pre>
  
  <p>But I don't want to do something like this, because <code>splitted</code> will remain in memory. I'm looking for a way to not saving this temporary data into memory.</p>
  
  <p>Is there any advice?</p>