指定したインデックス番号の属性を取得します。
[C#] C# では、このプロパティは AttributeCollection クラスのインデクサになります。
Overloads Public Overridable Default ReadOnly Property Item( _
ByVal index As Integer _) As Attribute
[C#]
public virtual Attribute this[intindex] {get;}
[C++]
public: __property virtual Attribute* get_Item(intindex);
[JScript]
returnValue = AttributeCollectionObject.Item(index);またはreturnValue = AttributeCollectionObject(index);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- index
AttributeCollection の 0 から始まるインデックス。
パラメータ [Visual Basic, C#, C++]
- index
AttributeCollection の 0 から始まるインデックス。
プロパティ値
指定したインデックス番号を持つ Attribute 。
解説
インデックス番号は 0 から始まっています。したがって、特定の Attribute にアクセスするには、その Attribute の位置を表す数値から 1 を引いた数値を使用する必要があります。たとえば、3 番目の Attribute を取得するには、 myColl[2]
と指定する必要があります。
使用例
Item プロパティを使用して、インデックス番号で指定した Attribute の名前をテキスト ボックスに出力する例を次に示します。インデックス番号は 0 から始まるため、この例では、2 番目の Attribute の名前がテキスト ボックスに出力されます。この例は、フォーム上に button1
と textBox1
が作成されていることを前提としています。
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
[C#]
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();
}
[C++]
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->Item[ 1 ]->ToString();
}
[JScript]
private function PrintIndexItem() {
// Creates a new collection and assigns it the attributes for button1.
var attributes : AttributeCollection;
attributes = TypeDescriptor.GetAttributes(button1);
// Prints the second attribute's name.
textBox1.Text = attributes[1].ToString();
Console.WriteLine(textBox1.Text);
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
AttributeCollection クラス | AttributeCollection メンバ | System.ComponentModel 名前空間 | AttributeCollection.Item オーバーロードの一覧 | Attribute