为什么XDocument.Descendants().Count()> 0表示空文档?

0 c# linq-to-xml

这是我的方法:

var document = XDocument.Parse(source);
if (document.Descendants().Count() > 0)
{
    // Some code that shouldn't execute
}
else
{
    // Code that should execute
}
Run Code Online (Sandbox Code Playgroud)

这个代码在'document'变量中时会中断:

<ipb></ipb>
Run Code Online (Sandbox Code Playgroud)

由于这不具有后代,为什么它进入IF条件?是不应该尝试加载任何东西,但它确实并且在它找不到任何东西时会中断.

使用断点我可以确认文档变量具有我在上面发布的内容,并且它确实输入了if.

Red*_*dog 5

你尝试过使用过:

document.Root.Descendants().Count() > 0;
Run Code Online (Sandbox Code Playgroud)

Root元素位于XDocument下方.