XElement.IsEmpty 속성

정의

이 요소에 콘텐츠가 없는지 여부를 나타내는 값을 가져옵니다.

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

속성 값

이 요소에 콘텐츠가 없으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 다양한 XML 트리를 만들고 각 트리와 함께 이 속성의 값을 보여 냅니다.

XElement el1 = new XElement("Root");
Console.WriteLine(el1);
Console.WriteLine(el1.IsEmpty);
Console.WriteLine();
XElement el2 = new XElement("Root", "content");
Console.WriteLine(el2);
Console.WriteLine(el2.IsEmpty);
Console.WriteLine();
XElement el3 = new XElement("Root", "");
Console.WriteLine(el3);
Console.WriteLine(el3.IsEmpty);
Console.WriteLine();
el3.ReplaceAll(null);
Console.WriteLine(el3);
Console.WriteLine(el3.IsEmpty);
Dim el1 As XElement = <Root/>
Console.WriteLine(el1)
Console.WriteLine(el1.IsEmpty)
Console.WriteLine()
Dim el2 As XElement = <Root>content</Root>
Console.WriteLine(el2)
Console.WriteLine(el2.IsEmpty)
Console.WriteLine()
Dim el3 As XElement = <Root></Root>
Console.WriteLine(el3)
Console.WriteLine(el3.IsEmpty)
Console.WriteLine()
el3.ReplaceAll(Nothing)
Console.WriteLine(el3)
Console.WriteLine(el3.IsEmpty)

이 예제는 다음과 같은 출력을 생성합니다.

<Root />
True

<Root>content</Root>
False

<Root></Root>
False

<Root />
True

설명

태그 사이에 콘텐츠가 없는 시작 태그와 끝 태그를 포함하는 요소는 빈 요소로 간주되지 않습니다. 길이가 없는 콘텐츠가 있습니다. 시작 태그만 포함하고 종료된 빈 요소로 표현되는 요소만 비어 있는 것으로 간주됩니다.

적용 대상

추가 정보