AttributeCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得具有指定索引的屬性。
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
取得具有指定索引號的屬性。 |
| Item[Type] |
取得指定類型的屬性。 |
Item[Int32]
取得具有指定索引號的屬性。
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
參數
- index
- Int32
的 AttributeCollection零基指數。
屬性值
該 具有 Attribute 指定的索引號。
範例
以下程式碼範例使用了 Item[] 該特性,將指定的名稱 Attribute 由索引號印入文字框中。 由於索引號是以零為基礎,此程式碼範例會在文字框中列印第二個 Attribute 索引的名稱。 它假設 button1 並 textBox1 被創造在一個形式上。
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
備註
指數號是以零為基礎。 因此,你必須從某個特定 Attribute 點的數值位置減去1才能取得該點 Attribute。 例如,要得到第三 Attribute個 ,你需要指定 myColl[2]。
另請參閱
適用於
Item[Type]
取得指定類型的屬性。
public:
virtual property Attribute ^ default[Type ^] { Attribute ^ get(Type ^ attributeType); };
public virtual Attribute this[Type attributeType] { get; }
member this.Item(Type) : Attribute
Default Public Overridable ReadOnly Property Item(attributeType As Type) As Attribute
參數
屬性值
該 Attribute 屬性為指定型別,或若屬性不存在,則為該屬性類型的預設值。
範例
以下程式碼範例從集合中取得 並 DesignerAttribute 列印其值。 它假設 且 button1textBox1 已被創造在一個表單上。
要執行此程式碼範例,您必須提供完全限定的組合名稱。 關於如何取得完全合格的議會名稱,請參閱議會名稱。
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
備註
如果該屬性不存在於集合中,這個屬性會回傳該屬性類型的預設值。