語言

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

適用於

另請參閱