title: How can I avoid .Average in a LINQ expression throwing an exception if there are no records?
body: <p>Here is the LINQ query that I have:</p>
  
  <pre><code> var t2 = t1.GroupBy(x =&gt; x.DateYYMMDD)
              .OrderBy(g =&gt; g.Key)
              .Select(g =&gt; new ScreenTimeModel
              {
                   DateYYMMDD = $"20{g.Key.Substring(0, 2)}/{g.Key.Substring(2, 2)}/{g.Key.Substring(4, 2)}",
                   LearnTimeAvg = (int)g.Where(gx =&gt; gx.Mode == 2).Average(gi =&gt; gi.ScreenSeconds)
              }).ToList();
  </code></pre>
  
  <p>Problems happen where there are no records meeting <code>Mode == 2</code>. </p>
  
  <p>Is there a way that I can default <code>LearntTimeAvg</code> to 0 in this case as presently it throws an exception and there's no list created?</p>