Share via


AttributeCollection.Item[] Properti

Definisi

Mendapatkan atribut dengan indeks yang ditentukan.

Overload

Item[Int32]

Mendapatkan atribut dengan nomor indeks yang ditentukan.

Item[Type]

Mendapatkan atribut dengan jenis yang ditentukan.

Item[Int32]

Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs

Mendapatkan atribut dengan nomor indeks yang ditentukan.

public:
 virtual property Attribute ^ default[int] { Attribute ^ get(int index); };
public virtual Attribute this[int index] { get; }
member this.Item(int) : Attribute
Default Public Overridable ReadOnly Property Item(index As Integer) As Attribute

Parameter

index
Int32

Indeks berbasis nol dari AttributeCollection.

Nilai Properti

Attribute dengan nomor indeks yang ditentukan.

Contoh

Contoh kode berikut menggunakan Item[] properti untuk mencetak nama Attribute yang ditentukan oleh nomor indeks dalam kotak teks. Karena nomor indeks berbasis nol, contoh kode ini mencetak nama yang kedua Attribute dalam kotak teks. Ini mengasumsikan button1 dan textBox1 telah dibuat pada formulir.

private:
   void PrintIndexItem()
   {
      // Creates a new collection and assigns it the attributes for button1.
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( button1 );
      
      // Prints the second attribute's name.
      textBox1->Text = attributes[ 1 ]->ToString();
   }
private void PrintIndexItem() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);

    // Prints the second attribute's name.
    textBox1.Text = attributes[1].ToString();
 }
Private Sub PrintIndexItem
    ' Creates a new collection and assigns it the attributes for button1.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)

    ' Prints the second attribute's name.
    textBox1.Text = attributes(1).ToString
End Sub

Keterangan

Nomor indeks berbasis nol. Oleh karena itu, Anda harus mengurangi 1 dari posisi numerik tertentu Attribute untuk mengaksesnya Attribute. Misalnya, untuk mendapatkan yang ketiga Attribute, Anda perlu menentukan myColl[2].

Lihat juga

Berlaku untuk

Item[Type]

Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs
Sumber:
AttributeCollection.cs

Mendapatkan atribut dengan jenis yang ditentukan.

public:
 virtual property Attribute ^ default[Type ^] { Attribute ^ get(Type ^ attributeType); };
public virtual Attribute this[Type attributeType] { get; }
public virtual Attribute? this[Type attributeType] { get; }
member this.Item(Type) : Attribute
Default Public Overridable ReadOnly Property Item(attributeType As Type) As Attribute

Parameter

attributeType
Type

dari TypeAttribute untuk mendapatkan dari koleksi.

Nilai Properti

Attribute dengan jenis yang ditentukan atau, jika atribut tidak ada, nilai default untuk jenis atribut.

Contoh

Contoh kode berikut mendapatkan DesignerAttribute dari koleksi dan mencetak nilainya. Ini mengasumsikan bahwa button1 dan textBox1 telah dibuat pada formulir.

Agar contoh kode ini berjalan, Anda harus memberikan nama rakitan yang sepenuhnya memenuhi syarat. Untuk informasi tentang cara mendapatkan nama rakitan yang sepenuhnya memenuhi syarat, lihat Nama Rakitan.

void PrintIndexItem2()
{
   
   // Creates a new collection and assigns it the attributes for button1.
   AttributeCollection^ attributes;
   attributes = TypeDescriptor::GetAttributes( button1 );
   
   // Gets the designer attribute from the collection.
   DesignerAttribute^ myDesigner;
   
   // You must supply a valid fully qualified assembly name here. 
   myDesigner = dynamic_cast<DesignerAttribute^>(attributes[ Type::GetType(  "Assembly text name, Version, Culture, PublicKeyToken" ) ]);
   textBox1->Text = myDesigner->DesignerTypeName;
}
private void PrintIndexItem2() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Gets the designer attribute from the collection.
    DesignerAttribute myDesigner; 
    // You must supply a valid fully qualified assembly name here. 
    myDesigner = (DesignerAttribute)attributes[Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")];
    textBox1.Text = myDesigner.DesignerTypeName;
 }
Private Sub PrintIndexItem2
    ' Creates a new collection and assigns it the attributes for button1.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)

    ' Gets the designer attribute from the collection.
    Dim myDesigner As DesignerAttribute
            ' You must supply a valid fully qualified assembly name here. 
    myDesigner = CType(attributes(Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")), DesignerAttribute)
    textBox1.Text = myDesigner.DesignerTypeName
End Sub

Keterangan

Jika atribut tidak ada dalam koleksi, properti ini mengembalikan nilai default untuk jenis atribut.

Lihat juga

Berlaku untuk