Share via


XmlSchemaObjectCollection.Add(XmlSchemaObject) 方法

定義

XmlSchemaObject 加入至 XmlSchemaObjectCollection

public:
 int Add(System::Xml::Schema::XmlSchemaObject ^ item);
public int Add (System.Xml.Schema.XmlSchemaObject item);
member this.Add : System.Xml.Schema.XmlSchemaObject -> int
Public Function Add (item As XmlSchemaObject) As Integer

參數

傳回

項目加入之處的索引。

例外狀況

index 小於零。

-或-

index 大於 Count

指定的 XmlSchemaObject 參數不屬於型別 XmlSchemaExternal 或其衍生型別 XmlSchemaImportXmlSchemaIncludeXmlSchemaRedefine

備註

如果 Count 已經等於容量,清單的容量會藉由自動重新配置內部陣列,並在新增專案之前將現有元素複製到新的陣列,來加倍清單的容量。

如果 Count 小於容量,這個方法是 0 (1) 作業。 如果需要增加容量以容納新元素,這個方法會變成 0 (n) 作業,其中 n 是 Count

方法 AddXmlSchemaExternal 預期和其衍生型別 (XmlSchemaImportXmlSchemaIncludeXmlSchemaRedefine) 做為參數。 下列範例說明如何將內含的架構新增至 Includes 現有 XmlSchema 物件的集合。

Dim schema As XmlSchema = New XmlSchema()  

Dim textReader As XmlTextReader = New XmlTextReader("include.xsd")  
Dim includeSchema As XmlSchema = XmlSchema.Read(textReader, null)  

Dim include As XmlSchemaInclude = New XmlSchemaInclude()  
include.Schema = includeSchema;  
schema.Includes.Add(include);  
XmlSchema schema = new XmlSchema();  

XmlTextReader textReader = new XmlTextReader("include.xsd");  
XmlSchema includeSchema = XmlSchema.Read(textReader, null);  

XmlSchemaInclude include = new XmlSchemaInclude();  
include.Schema = includeSchema;  
schema.Includes.Add(include);  

適用於