PropertyDescriptorCollection.Item[] Property

Definition

Gets or sets the specified PropertyDescriptor.

Overloads

Item[Int32]

Gets or sets the PropertyDescriptor at the specified index number.

Item[String]

Gets or sets the PropertyDescriptor with the specified name.

Item[Int32]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs

Gets or sets the PropertyDescriptor at the specified index number.

C#
public virtual System.ComponentModel.PropertyDescriptor this[int index] { get; }

Parameters

index
Int32

The zero-based index of the PropertyDescriptor to get or set.

Property Value

The PropertyDescriptor with the specified index number.

Exceptions

The index parameter is not a valid index for Item[Int32].

Examples

The following code example uses the Item[] property to print the name of the PropertyDescriptor specified by the index number in a text box. Because the index number is zero-based, this example prints the name of the second PropertyDescriptor. It requires that button1 has been instantiated on a form.

C#
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();
 }

Remarks

The index number is zero-based. Therefore, you must subtract 1 from the numerical position of a particular PropertyDescriptor to access that PropertyDescriptor. For example, to get the third PropertyDescriptor, you need to specify myColl[2].

See also

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[String]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs

Gets or sets the PropertyDescriptor with the specified name.

C#
public virtual System.ComponentModel.PropertyDescriptor? this[string name] { get; }
C#
public virtual System.ComponentModel.PropertyDescriptor this[string name] { get; }

Parameters

name
String

The name of the PropertyDescriptor to get from the collection.

Property Value

The PropertyDescriptor with the specified name, or null if the property does not exist.

Examples

The following code example uses the Item[] property to print the type of component for the PropertyDescriptor specified by the index. It requires that button1 and textBox1 have been instantiated on a form.

C#
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;
}

Remarks

The Item[] property is case-sensitive when searching for names. That is, the names "Pname" and "pname" are considered to be two different properties.

See also

Applies to

.NET 10 an aner Versiounen
Produkt Versiounen
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1