XElement.HasAttributes 屬性

定義

取得值,指出這個項目是否至少有一個屬性。

public:
 property bool HasAttributes { bool get(); };
public bool HasAttributes { get; }
member this.HasAttributes : bool
Public ReadOnly Property HasAttributes As Boolean

屬性值

如果這個項目至少有一個屬性,則為 true;否則為 false

範例

下列範例會使用這個屬性。

XElement xmlTree1 = new XElement("Root",
    new XAttribute("Att1", 1)
);
Console.WriteLine(xmlTree1.HasAttributes);
XElement xmlTree2 = new XElement("Root");
Console.WriteLine(xmlTree2.HasAttributes);
Dim xmlTree1 As XElement = <Root Att1="1"/>
Console.WriteLine(xmlTree1.HasAttributes)

Dim xmlTree2 As XElement = <Root/>
Console.WriteLine(xmlTree2.HasAttributes)

這個範例會產生下列輸出:

True
False

適用於

另請參閱