PropertyDescriptorCollection.Item[] Свойство

Определение

Получает или задает указанный объект PropertyDescriptor.

Перегрузки

Item[Int32]

Получает или задает дескриптор PropertyDescriptor с заданным индексом.

Item[String]

Возвращает или задает объект PropertyDescriptor с заданным именем.

Item[Int32]

Исходный код:
PropertyDescriptorCollection.cs
Исходный код:
PropertyDescriptorCollection.cs
Исходный код:
PropertyDescriptorCollection.cs

Получает или задает дескриптор PropertyDescriptor с заданным индексом.

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

Параметры

index
Int32

Индекс (с нуля) возвращаемого или задаваемого PropertyDescriptor.

Значение свойства

Объект PropertyDescriptor с заданным индексом.

Исключения

Параметр index является недопустимым индексом Item[Int32] .

Примеры

В следующем примере кода свойство используется для Item[] вывода имени, указанного PropertyDescriptor номером индекса, в текстовом поле. Так как число индекса отсчитывается от нуля, в этом примере выводится имя второго PropertyDescriptor. Для этого требуется, чтобы button1 экземпляр был создан в форме.

void PrintIndexItem()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Prints the second property's name.
   textBox1->Text = properties[ 1 ]->ToString();
}
private void PrintIndexItem() {
    // Creates a new collection and assigns it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Prints the second property's name.
    textBox1.Text = properties[1].ToString();
 }
Private Sub PrintIndexItem()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
       
    ' Prints the second property's name.
    textBox1.Text = properties(1).ToString()
End Sub

Комментарии

Номер индекса отсчитывается от нуля. Поэтому необходимо вычесть 1 из числового положения конкретного PropertyDescriptor объекта, чтобы получить доступ к этой PropertyDescriptor. Например, чтобы получить третий PropertyDescriptor, необходимо указать myColl[2].

См. также раздел

Применяется к

Item[String]

Исходный код:
PropertyDescriptorCollection.cs
Исходный код:
PropertyDescriptorCollection.cs
Исходный код:
PropertyDescriptorCollection.cs

Возвращает или задает объект PropertyDescriptor с заданным именем.

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

Параметры

name
String

Имя дескриптора PropertyDescriptor, который нужно получить из коллекции.

Значение свойства

Дескриптор PropertyDescriptor с заданным именем или null, если свойство не существует.

Примеры

В следующем примере кода свойство используется для Item[] печати типа компонента для указанного PropertyDescriptor индексом. Для этого требуется, чтобы button1 экземпляры и textBox1 были созданы в форме.

void PrintIndexItem2()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor^ myProperty = properties[ "Opacity" ];
   
   // Prints the display name for the property.
   textBox1->Text = myProperty->DisplayName;
}
private void PrintIndexItem2() {
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection properties =
       TypeDescriptor.GetProperties(button1);

   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor myProperty = properties["Opacity"];

   // Prints the display name for the property.
   textBox1.Text = myProperty.DisplayName;
}
Private Sub PrintIndexItem2()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = _
       TypeDescriptor.GetProperties(button1)
       
    ' Sets a PropertyDescriptor to the specific property.
    Dim myProperty As PropertyDescriptor = properties("Opacity")
       
    ' Prints the display name for the property.
    textBox1.Text = myProperty.DisplayName
End Sub

Комментарии

Свойство Item[] учитывает регистр при поиске имен. То есть имена "Pname" и "pname" считаются двумя разными свойствами.

См. также раздел

Применяется к