Assign and check for a null value at the same time?

A variable assignment also returns the value. So the syntax in the form of the following will do:

SomeType someVariable;
if ((someVariable = valueToAssign) != null)
{
    // valueToAssign was not null
}

In your case:

XElement children;

if ((children = xml.Descendants(ns + "Children").FirstOrDefault()) != null)
{

}

I would do it this way:

XElement children = xml.Descendants(ns + "Children").FirstOrDefault();
if(children != null)
{
    //use children
}

You could just do

XElement children = xml.Descendants(ns + "Children").FirstOrDefault();

and then check for null

if (children != null) {...}

Tags:

C#