如何在xml数据的linq查询中使用TryParse?

Sta*_*Csh 12 c# xml linq

我正在处理每日股票市场数据的内存xml,我得到其中一个日期的值"8/221/19055".我看到TryParse可能是检查有效日期的最佳选择,但MSDN doc似乎对第二个参数"out DateTime result"的解释很清楚.我如何在下面的linq查询中使用它?

var makeInfo =
         from s in doc.Descendants("quote")
         where s.Element("LastTradeDate") != null
                && s.Attribute("symbol") != null
         let dateStr = s.Element("LastTradeDate").Value
         where !string.IsNullOrEmpty(dateStr)
                && DateTime.Parse(dateStr, enUS) == targetDate
         select new DailyPricingVolDP((string)s.Attribute("symbol"),
                                      (DateTime)s.Element("LastTradeDate"),
                                      (double)s.Element("Open"),
                                      (double)s.Element("DaysHigh"),
                                      (double)s.Element("DaysLow"),  
                                      (double)s.Element("LastTradePriceOnly"),
                                       (long)s.Element("Volume"));
Run Code Online (Sandbox Code Playgroud)

Jen*_*zlo 13

Func<string, DateTime?> tryToGetDate =
        value =>
            {
                DateTime dateValue;
                return DateTime.TryParse(value, out dateValue) ? (DateTime?) dateValue : null;
            };

    var makeInfo =
         from s in doc.Descendants("quote")
         where s.Element("LastTradeDate") != null
                && s.Attribute("symbol") != null
         let dateStr = s.Element("LastTradeDate").Value
         let dateValue = tryToGetDate(dateStr)
         where dateValue != null && (DateTime)dateValue == targetDate
         select .... etc etc
Run Code Online (Sandbox Code Playgroud)