PropertyDescriptorCollection.IDictionary.GetEnumerator 方法

定義

傳回這個類別的列舉值。

C#
System.Collections.IDictionaryEnumerator IDictionary.GetEnumerator ();

傳回

IEnumerator 型別的列舉程式。

實作

範例

下列程式代碼範例會取得 上 button1屬性的列舉值。 它會使用列舉值來列印集合中屬性的名稱。 它要求 button1 已在表單上具現化 和 textBox1

C#
private void MyEnumerator() {
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

   // Creates an enumerator.
   IEnumerator ie = properties.GetEnumerator();

   // Prints the name of each property in the collection.
   Object myProperty;
   while(ie.MoveNext()==true) {
      myProperty = ie.Current;
      textBox1.Text += myProperty.ToString() + '\n';
   }
}

適用於

產品 版本
.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
.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

另請參閱