次のシナリオがあります。
if(xml.Descendants(ns + "Children").FirstOrDefault() != null)
{
XElement children = xml.Descendants(ns + "Children").FirstOrDefault();
}
次のように、値を2回検索する代わりに、nullをチェックし、同時に値を割り当てる方法はありますか?
//Not sure if this is correct.
if (XElement children = xml.Descendants(ns + "Children").FirstOrDefault() != null)
{
}