XmlReader.Item[] 屬性

定義

在衍生類別中覆寫時,取得屬性值。

多載

Item[Int32]

在衍生類別中覆寫時,取得具有指定索引的屬性值。

Item[String]

在衍生類別中覆寫時,取得具有指定 Name 的屬性值。

Item[String, String]

在衍生類別中覆寫時,取得具有指定 LocalNameNamespaceURI 的屬性值。

Item[Int32]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

在衍生類別中覆寫時,取得具有指定索引的屬性值。

public:
 virtual property System::String ^ default[int] { System::String ^ get(int i); };
public:
 abstract property System::String ^ default[int] { System::String ^ get(int i); };
public virtual string this[int i] { get; }
public abstract string this[int i] { get; }
member this.Item(int) : string
Default Public Overridable ReadOnly Property Item(i As Integer) As String
Default Public MustOverride ReadOnly Property Item(i As Integer) As String

參數

i
Int32

屬性的索引。

屬性值

指定的屬性值。

例外狀況

在先前的非同步作業完成前呼叫了 XmlReader 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

範例

下列範例會顯示目前節點上的所有屬性。

// Display all attributes.
if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  for (int i = 0; i < reader.AttributeCount; i++) {
    Console.WriteLine("  {0}", reader[i]);
  }
  // Move the reader back to the element node.
  reader.MoveToElement();
}
' Display all attributes.
If reader.HasAttributes Then
  Console.WriteLine("Attributes of <" + reader.Name + ">")
  Dim i As Integer
  For i = 0 To (reader.AttributeCount - 1)
    Console.WriteLine("  {0}", reader(i))
  Next i
  ' Move the reader back to the element node.
  reader.MoveToElement() 
End If

備註

此屬性不會移動讀取器。

另請參閱

適用於

Item[String]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

在衍生類別中覆寫時,取得具有指定 Name 的屬性值。

public:
 virtual property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); };
public:
 abstract property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); };
public virtual string this[string name] { get; }
public virtual string? this[string name] { get; }
public abstract string this[string name] { get; }
member this.Item(string) : string
Default Public Overridable ReadOnly Property Item(name As String) As String
Default Public MustOverride ReadOnly Property Item(name As String) As String

參數

name
String

屬性的限定名稱 (Qualified Name)。

屬性值

指定的屬性值。 如果找不到屬性,會傳回 null

例外狀況

在先前的非同步作業完成前呼叫了 XmlReader 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

範例

下列範例會取得 ISBN 屬性的值。

reader.ReadToDescendant("book");
string isbn =reader["ISBN"];
Console.WriteLine("The ISBN value: " + isbn);
reader.ReadToDescendant("book")
Dim isbn As String = reader("ISBN")
Console.WriteLine("The ISBN value: " + isbn)

備註

此屬性不會移動讀取器。

如果讀取器位於 DocumentType 節點上,則這個方法可用來取得 PUBLIC 和 SYSTEM 常值,例如 reader["PUBLIC"]

另請參閱

適用於

Item[String, String]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

在衍生類別中覆寫時,取得具有指定 LocalNameNamespaceURI 的屬性值。

public:
 virtual property System::String ^ default[System::String ^, System::String ^] { System::String ^ get(System::String ^ name, System::String ^ namespaceURI); };
public:
 abstract property System::String ^ default[System::String ^, System::String ^] { System::String ^ get(System::String ^ name, System::String ^ namespaceURI); };
public virtual string this[string name, string namespaceURI] { get; }
public virtual string? this[string name, string? namespaceURI] { get; }
public abstract string this[string name, string namespaceURI] { get; }
member this.Item(string * string) : string
Default Public Overridable ReadOnly Property Item(name As String, namespaceURI As String) As String
Default Public MustOverride ReadOnly Property Item(name As String, namespaceURI As String) As String

參數

name
String

屬性的本機名稱。

namespaceURI
String

屬性的命名空間 URI。

屬性值

指定的屬性值。 如果找不到屬性,會傳回 null

例外狀況

在先前的非同步作業完成前呼叫了 XmlReader 方法。 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。

備註

此屬性不會移動讀取器。

另請參閱

適用於