文件说:
XContainer.Nodes Method()按文档顺序返回此元素或文档的子节点的集合.
备注请注意,内容不包含属性.在LINQ to XML中,属性不被视为树的节点.它们是与元素关联的名称/值对.
XContainer.Elements Method()按文档顺序返回此元素或文档的子元素的集合.
所以它看起来像Nodes()有一个限制,但那为什么它存在?使用节点()有任何可能的原因或优点吗?
这是我的测试:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace asynktest
{
class Program
{
static async Task Main(string[] args)
{
var t = Test1(true);
await t; //throws InvalidOperationException here. correct
t = Test1(false);
await t; //throws NotImplementedException here. correct
t = Test2(true); //throws InvalidOperationException here. wrong
await t;
t = Test2(false); //throws NotImplementedException here. wrong
await t;
t = Test3(true);
await t; //throws InvalidOperationException here. correct
t = Test3(false); //throws NotImplementedException here. wrong
await t;
t = …Run Code Online (Sandbox Code Playgroud)