title: How can I test if a string can be converted to a decimal in Linq?
body: <p>I'm trying to extract some data from XML using Linq to XML, and I have the following code:</p>
  
  <pre><code>            commisionPct = XDocument.Parse(commissionXml)
                                      .Descendants("Range")
                                      .Attributes("commission")
                                      .Select(x =&gt; Convert.ToDecimal(x.Value))
                                      .FirstOrDefault();
  </code></pre>
  
  <p>The problem is I do not want it to exception if <code>x.Value</code> is not a decimal.  Normally I'd use <code>decimal.TryParse</code> but I am not sure of a clean way to do this inside of a linq statement.  I guess I could surround this with a try/catch block but I was curious if there was a better way to do this inside of Linq. </p>
  
  <p>I would prefer it to return the decimal default value (0) if it's not a decimal.</p>