XObject.Parent 属性 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public:
 property System::Xml::Linq::XElement ^ Parent { System::Xml::Linq::XElement ^ get(); };public System.Xml.Linq.XElement Parent { get; }public System.Xml.Linq.XElement? Parent { get; }member this.Parent : System.Xml.Linq.XElementPublic ReadOnly Property Parent As XElement属性值
示例
以下示例使用此方法。
XDocument doc = new XDocument(
    new XComment("A comment in the document."),
    new XElement("Root",
        new XElement("Child", "content")
    )
);
XElement child = doc.Descendants("Child").First();
XElement root = child.Parent;
Console.WriteLine(root.Name);
Dim doc As XDocument = _
    <?xml version="1.0"?>
    <!--A comment in the document.-->
    <Root>
        <Child>content</Child>
    </Root>
Dim child As XElement = doc.Descendants("Child").First()
Dim root As XElement = child.Parent
Console.WriteLine(root.Name)
该示例产生下面的输出:
Root
注解
如果它 XObject 没有父元素,则此属性返回 null。
注意
此属性返回父元素,并且由于 的 XDocument 子节点没有父元素,此属性为它们返回 null 。