XStreamingElement.Add 方法

定義

將指定的內容當做子系加入至這個 XStreamingElementAdds the specified content as children to this XStreamingElement.

多載

Add(Object)

將指定的內容當做子系加入至這個 XStreamingElementAdds the specified content as children to this XStreamingElement.

Add(Object[])

將指定的內容當做子系加入至這個 XStreamingElementAdds the specified content as children to this XStreamingElement.

Add(Object)

將指定的內容當做子系加入至這個 XStreamingElementAdds the specified content as children to this XStreamingElement.

public:
 void Add(System::Object ^ content);
public void Add (object content);
member this.Add : obj -> unit
Public Sub Add (content As Object)

參數

content
Object

要加入到資料流項目的內容。Content to be added to the streaming element.

範例

下列範例會建立新的 XStreamingElementThe following example creates a new XStreamingElement. 然後,它會將兩個查詢新增至串流元素。It then adds two queries to the streaming element. 查詢不會反復進行,直到串流元素序列化為止。The queries are not iterated until the streaming element is serialized.

XElement srcTree = new XElement("Root",  
                       new XElement("Child", 1),  
                       new XElement("Child", 2),  
                       new XElement("Child", 3),  
                       new XElement("Child", 4),  
                       new XElement("Child", 5)  
                   );  

XStreamingElement dstTree = new XStreamingElement("NewRoot");  

dstTree.Add(  
    from el in srcTree.Elements()  
    where (int)el <= 1  
    select new XElement("Child", (int)el)  
);  

dstTree.Add(  
    from el in srcTree.Elements()  
    where (int)el >= 3  
    select new XElement("DifferentChild", (int)el)  
);  

Console.WriteLine(dstTree);  
Dim srcTree As XElement = _  
    <Root>  
        <Child>1</Child>  
        <Child>2</Child>  
        <Child>3</Child>  
        <Child>4</Child>  
        <Child>5</Child>  
    </Root>  

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot")  

dstTree.Add( _  
    From el In srcTree.Elements() _  
    Where el.Value <= 1 _  
    Select <Child><%= el.Value %></Child> _  
)  

dstTree.Add( _  
    From el In srcTree.Elements() _  
    Where el.Value >= 3 _  
    Select <DifferentChild><%= el.Value %></DifferentChild> _  
)  

Console.WriteLine(dstTree)  

這個範例會產生下列輸出:This example produces the following output:

<NewRoot>  
  <Child>1</Child>  
  <DifferentChild>3</DifferentChild>  
  <DifferentChild>4</DifferentChild>  
  <DifferentChild>5</DifferentChild>  
</NewRoot>  

備註

這個函式會將指定的內容和屬性加入至 XStreamingElementThis constructor adds the specified content and attributes to the XStreamingElement. 雖然通常可以 XStreamingElement 在單一語句中建立,但是將內容以累加方式新增至串流元素有時比較方便。While it is often possible to construct the XStreamingElement in a single statement, it is sometimes more convenient to add content to the streaming element incrementally.

查詢不會反復進行,直到 XStreamingElement 序列化為止。Queries are not iterated until the XStreamingElement is serialized. 這與使用的內容查詢不同,在新的建立時,會反復查看 XElement 查詢 XElementThis is in contrast to using queries for content for an XElement, where queries are iterated at the time of construction of the new XElement.

如需可傳遞給此函式之有效內容的詳細資訊,請參閱 system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

另請參閱

Add(Object[])

將指定的內容當做子系加入至這個 XStreamingElementAdds the specified content as children to this XStreamingElement.

public:
 void Add(... cli::array <System::Object ^> ^ content);
public void Add (params object[] content);
member this.Add : obj[] -> unit
Public Sub Add (ParamArray content As Object())

參數

content
Object[]

要加入到資料流項目的內容。Content to be added to the streaming element.

範例

下列範例會建立新的 XStreamingElementThe following example creates a new XStreamingElement. 然後,它會將兩個查詢新增至串流元素。It then adds two queries to the streaming element. 查詢不會反復進行,直到串流元素序列化為止。The queries are not iterated until the streaming element is serialized.

XElement srcTree = new XElement("Root",  
                       new XElement("Child", 1),  
                       new XElement("Child", 2),  
                       new XElement("Child", 3),  
                       new XElement("Child", 4),  
                       new XElement("Child", 5)  
                   );  

XStreamingElement dstTree = new XStreamingElement("NewRoot");  

dstTree.Add(  
    from el in srcTree.Elements()  
    where (int)el <= 1  
    select new XElement("Child", (int)el)  
);  

dstTree.Add(  
    from el in srcTree.Elements()  
    where (int)el >= 3  
    select new XElement("DifferentChild", (int)el)  
);  

Console.WriteLine(dstTree);  
Dim srcTree As XElement = _  
    <Root>  
        <Child>1</Child>  
        <Child>2</Child>  
        <Child>3</Child>  
        <Child>4</Child>  
        <Child>5</Child>  
    </Root>  

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot")  

dstTree.Add( _  
    From el In srcTree.Elements() _  
    Where el.Value <= 1 _  
    Select <Child><%= el.Value %></Child> _  
)  

dstTree.Add( _  
    From el In srcTree.Elements() _  
    Where el.Value >= 3 _  
    Select <DifferentChild><%= el.Value %></DifferentChild> _  
)  

Console.WriteLine(dstTree)  

這個範例會產生下列輸出:This example produces the following output:

<NewRoot>  
  <Child>1</Child>  
  <DifferentChild>3</DifferentChild>  
  <DifferentChild>4</DifferentChild>  
  <DifferentChild>5</DifferentChild>  
</NewRoot>  

備註

這個函式會將指定的內容和屬性加入至 XStreamingElementThis constructor adds the specified content and attributes to the XStreamingElement. 雖然通常可以 XStreamingElement 在單一語句中建立,但是將內容以累加方式新增至串流元素有時比較方便。While it is often possible to construct the XStreamingElement in a single statement, it is sometimes more convenient to add content to the streaming element incrementally.

查詢不會反復進行,直到 XStreamingElement 序列化為止。Queries are not iterated until the XStreamingElement is serialized. 這與使用的內容查詢不同,在新的建立時,會反復查看 XElement 查詢 XElementThis is in contrast to using queries for content for an XElement, where queries are iterated at the time of construction of the new XElement.

如需可傳遞給此函式之有效內容的詳細資訊,請參閱 system.xml.linq.xelement> 和 XDocument 物件的有效內容For details about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects.

另請參閱

適用於